]> git.eshelyaron.com Git - emacs.git/commitdiff
Calc parses fractions written using U+2044 FRACTION SLASH
authorDaniel Brooks <db48x@db48x.net>
Sun, 5 Nov 2023 08:03:37 +0000 (01:03 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 31 Jan 2024 20:09:13 +0000 (21:09 +0100)
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.  (Bug#66944)

* test/lisp/calc/calc-tests.el (calc-frac-input): Test various
fraction types.

* etc/NEWS:
* doc/misc/calc.texi (Fractions): Mention fraction slash, precomposed
fractions.

Copyright-paperwork-exempt: yes
(cherry picked from commit 77d9d05df87965409c537f49d59cb5ea632abda1)

doc/misc/calc.texi
etc/NEWS
lisp/calc/calc-aent.el
test/lisp/calc/calc-tests.el

index 7ae338307a580e16eff1b5a022d79fa3b64954e7..31db77a072045c2919b761d0cb16df81be00ee6a 100644 (file)
@@ -10571,6 +10571,22 @@ Non-decimal fractions are entered and displayed as
 @samp{@var{radix}#@var{num}:@var{denom}} (or in the analogous three-part
 form).  The numerator and denominator always use the same radix.
 
+@ifnottex
+Fractions may also be entered with @kbd{@U{2044}} (U+2044 FRACTION
+SLASH) in place of any @kbd{:}.  Precomposed fraction characters from
+@kbd{@U{00BD}} (U+00BD VULGAR FRACTION ONE HALF) through
+@kbd{@U{215E}} (U+215E VULGAR FRACTION SEVEN EIGHTHS) as supported as
+well.  Thus @samp{2:3}, @samp{2@U{2044}3}, and @samp{@U{2154}} are all
+equivalent.
+@end ifnottex
+@iftex
+Fractions may also be entered with U+2044 FRACTION SLASH in place of
+any @kbd{:}.  Precomposed fraction characters from U+00BD VULGAR
+FRACTION ONE HALF through U+215E VULGAR FRACTION SEVEN EIGHTHS as
+supported as well.
+@end iftex
+
+
 @node Floats
 @section Floats
 
index b8626fa2fab29536e5365ede03ad64c18691e3d5..a2ce782af174ed14acc18739e958d8c75ee6646a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1389,7 +1389,16 @@ This user option lets you customize the sample text that
 +++
 *** 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.  You may also be interested to know that precomposed
+fraction characters, such as ½ (U+00BD VULGAR FRACTION ONE HALF), are
+also recognized as rational fractions.  They have been since 2004, but
+it looks like it was never mentioned in the NEWS, or even the manual.
 \f
 * New Modes and Packages in Emacs 30.1
 
index 08e8d9fcd6f8d03e60c1820b09344541caecdac0..a21efc0238d463707bdb9fae9a5ac33d371a52b1 100644 (file)
@@ -505,6 +505,7 @@ The value t means abort and give an error message.")
     ("⅝" "(5:8)") ; 5/8
     ("⅞" "(7:8)") ; 7/8
     ("⅟" "1:")    ; 1/...
+    ("⁄" ":")     ; arbitrary fractions of the form 123⁄456
     ;; superscripts
     ("⁰" "0")  ; 0
     ("¹" "1")  ; 1
index a44a5898055364c88a9523ed752666b4ff964426..d96672c04a19e00db9c50866fc839e9fbd926e3a 100644 (file)
@@ -734,6 +734,31 @@ An existing calc stack is reused, otherwise a new one is created."
                             (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'.