Thanks for the report! I've taken your suggestion for ~r's order-of-magnitude estimate. (I didn't change the version in racket/math, though, but it seems like a reasonable idea to me.)

Ryan

On 05/08/2013 03:21 AM, Jos Koot wrote:
I came across another thing:

#lang racket

(define x #e100.e-50000)
(rational? x) ; #t
(log x) ; -inf.0
(exact->inexact x); 0.0
(~r x #:notation 'exponential) ; error inexact->exact: no exact
representation
   number: -inf.0

I think this is introduced in line 340 of racket/format.rkt which contains:
(inexact->exact (floor (/ (log N-abs) (log base))))
for the first estimate of the order of magnitude.

As the docs of ~r say "The exactness or inexactness of x does not affect its
formatting.", this behaviour may well be intentional.

It is possible though to avoid the error by subtracting the log of the
denominator from that of the nominator after conversion to exact rational.
Proc order-of-magnitude (in math I think) does this, but is for base 10
only. May be I should adapt order-of-magnitude such as to accept a base
argument?

Best wishes, Jos

-----Original Message-----
From: users-boun...@racket-lang.org
[mailto:users-boun...@racket-lang.org] On Behalf Of Dmitry Pavlov
Sent: martes, 07 de mayo de 2013 19:12
To: users@racket-lang.org
Subject: [racket] ~r: formatting 0.0 with 'exponential and #:precision

Hello,

I just came across the following oddness with formatting
of real numbers:

  > (~r 1.0 #:notation 'exponential #:precision '(= 4))
"1.0000e+00"

OK


  > (~r 0.0 #:notation 'exponential #:precision '(= 4))
"0.e+04"

???

Is there a rational explanation of why did
the requested precision go into the exponent
number for 0.0?

Thanks.


Best regards,

Dmitry
____________________
   Racket Users list:
   http://lists.racket-lang.org/users

____________________
   Racket Users list:
   http://lists.racket-lang.org/users


____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to