mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 22:10:21 +02:00
Fix parsing of exact numbers with negative exponents
* libguile/numbers.c (mem2decimal_from_point): Use scm_divide instead of scm_divide2real when applying a negative exponent, to preserve exactness in case the "#e" forced exactness specifier is present. This fixes a bug where numeric literals such as "#e1e-5" yielded incorrect fractions.
This commit is contained in:
parent
ce6066065d
commit
6ebecdeb7d
2 changed files with 6 additions and 1 deletions
|
@ -5668,7 +5668,7 @@ mem2decimal_from_point (SCM result, SCM mem,
|
|||
if (sign == 1)
|
||||
result = scm_product (result, e);
|
||||
else
|
||||
result = scm_divide2real (result, e);
|
||||
result = scm_divide (result, e);
|
||||
|
||||
/* We've seen an exponent, thus the value is implicitly inexact. */
|
||||
x = INEXACT;
|
||||
|
|
|
@ -1456,6 +1456,11 @@
|
|||
(pass-if (string=? (number->string 35 36) "z"))
|
||||
(pass-if (= (num->str->num 35 36) 35))
|
||||
|
||||
;; Before Guile 2.0.1, even in the presence of a #e forced exactness
|
||||
;; specifier, negative exponents were applied inexactly and then
|
||||
;; later coerced to exact, yielding an incorrect fraction.
|
||||
(pass-if (eqv? (string->number "#e1e-10") 1/10000000000))
|
||||
|
||||
;; Numeric conversion from decimal is not precise, in its current
|
||||
;; implementation, so 11.333... and 1.324... can't be expected to
|
||||
;; reliably come out to precise values. These tests did actually work
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue