bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#66944: 30.0.50; [PATCH] make calc parse fractions written using U+20


From: Daniel Brooks
Subject: bug#66944: 30.0.50; [PATCH] make calc parse fractions written using U+2044 FRACTION SLASH
Date: Sat, 13 Jan 2024 08:11:27 -0800
User-agent: Gnus/5.13 (Gnus v5.13)

Stefan Kangas <stefankangas@gmail.com> writes:

> Daniel Brooks <db48x@db48x.net> writes:
>
>> Fractions written as `2:3', `2÷3', and `⅔' are all parsed as rational
>> fractions; `2⁄3' ought to do the same.
>
> Thanks, but was the intention here to attach a patch?
>
> I can't see one attached, so maybe you missed it.

/me facepalms

Yea, dunno how that happened. Let me try again, this time with my tongue
held at just the right angle…

>From be3fa086c20909993d32d430a7f0d315db8fcb49 Mon Sep 17 00:00:00 2001
From: Daniel Brooks <db48x@db48x.net>
Date: Sun, 5 Nov 2023 01:03:37 -0700
Subject: [PATCH] Calc parses fractions written using U+2044 FRACTION SLASH
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Fractions of the form 123⁄456 are handled as if written 123:456. Note
in particular the difference in behavior from U+2215 DIVISION SLASH
and U+002F SOLIDUS, which result in division rather than a rational
fraction.

* lisp/calc/calc-aent.el (math-read-replacement-list): Substitute a
colon for any fraction slash.
* test/lisp/calc/calc-tests.el (calc-frac-input): Test various
fraction types.
* doc/misc/calc.texi (Fractions): Mention fraction slash, precomposed
fractions.

Copyright-paperwork-exempt: yes
---
 doc/misc/calc.texi           |  6 ++++++
 etc/NEWS                     |  7 ++++++-
 lisp/calc/calc-aent.el       |  1 +
 test/lisp/calc/calc-tests.el | 25 +++++++++++++++++++++++++
 4 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/doc/misc/calc.texi b/doc/misc/calc.texi
index c651b007173..3030df0c101 100644
--- a/doc/misc/calc.texi
+++ b/doc/misc/calc.texi
@@ -10571,6 +10571,12 @@ Fractions
 @samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part
 form).  The numerator and denominator always use the same radix.
 
+Fractions may also be entered with @kbd{⁄} (U+2044 FRACTION SLASH) in
+place of any @kbd{:}. Precomposed fraction characters from @kbd{½}
+(U+00BD VULGAR FRACTION ONE HALF) through @kbd{⅞} (U+215E VULGAR
+FRACTION SEVEN EIGHTHS) as supported as well. Thus @samp{2:3},
+@samp{2⁄3}, and @samp{⅔} are all equivalent.
+
 @node Floats
 @section Floats
 
diff --git a/etc/NEWS b/etc/NEWS
index e29a787a0cc..038ebf1b925 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -983,7 +983,12 @@ URIs are now prefixed with "https://"; instead.
 +++
 *** New command 'customize-dirlocals'.
 This command pops up a buffer to edit the settings in ".dir-locals.el".
-
+** Calc
+*** Calc parses fractions written using U+2044 FRACTION SLASH
+Fractions of the form 123⁄456 are handled as if written 123:456. Note
+in particular the difference in behavior from U+2215 DIVISION SLASH
+and U+002F SOLIDUS, which result in division rather than a rational
+fraction.

 * New Modes and Packages in Emacs 30.1
 
diff --git a/lisp/calc/calc-aent.el b/lisp/calc/calc-aent.el
index 66ede3295ae..1dcb9ad1c85 100644
--- a/lisp/calc/calc-aent.el
+++ b/lisp/calc/calc-aent.el
@@ -505,6 +505,7 @@ math-read-replacement-list
     ("⅝" "(5:8)") ; 5/8
     ("⅞" "(7:8)") ; 7/8
     ("⅟" "1:")    ; 1/...
+    ("⁄" ":")     ; arbitrary fractions of the form 123⁄456
     ;; superscripts
     ("⁰" "0")  ; 0
     ("¹" "1")  ; 1
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 5b11dd950ba..e724295e8e0 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -734,6 +734,31 @@ calc-latex-input
                             (var c var-c))))))
     (calc-set-language nil)))
 
+(ert-deftest calc-frac-input ()
+  ;; precomposed fraction
+  (should (equal (math-read-expr "½")
+                 '(frac 1 2)))
+  ;; ascii solidus
+  (should (equal (math-read-expr "123/456")
+                 '(/ 123 456)))
+  (should (equal (math-read-expr "a/b")
+                 '(/ (var a var-a) (var b var-b))))
+  ;; fraction slash
+  (should (equal (math-read-expr "123⁄456")
+                 '(frac 41 152)))
+  (should (equal (math-read-expr "a⁄b")
+                 '(error 1 "Syntax error")))
+  ;; division slash
+  (should (equal (math-read-expr "123∕456")
+                 '(/ 123 456)))
+  (should (equal (math-read-expr "a∕b")
+                 '(/ (var a var-a) (var b var-b))))
+  ;; division sign
+  (should (equal (math-read-expr "123÷456")
+                 '(frac 41 152)))
+  (should (equal (math-read-expr "a÷b") ; I think this one is wrong
+                 '(error 1 "Syntax error"))))
+
 (defvar var-g)
 
 ;; Test `let'.
-- 
2.41.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]