1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

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.
* 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
This commit is contained in:
Daniel Brooks 2023-11-05 01:03:37 -07:00 committed by Eli Zaretskii
parent 63a12ffbc3
commit 77d9d05df8
4 changed files with 52 additions and 1 deletions

View 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

View File

@ -1288,7 +1288,16 @@ chat buffers use by default.
+++
*** 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 123456 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.
* New Modes and Packages in Emacs 30.1

View 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 123456
;; superscripts
("" "0") ; 0
("¹" "1") ; 1

View 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 "123456")
'(frac 41 152)))
(should (equal (math-read-expr "ab")
'(error 1 "Syntax error")))
;; division slash
(should (equal (math-read-expr "123456")
'(/ 123 456)))
(should (equal (math-read-expr "ab")
'(/ (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'.