[racket] ~r: formatting 0.0 with 'exponential and #:precision

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Wed May 8 12:57:43 EDT 2013

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-bounces at racket-lang.org
>> [mailto:users-bounces at racket-lang.org] On Behalf Of Dmitry Pavlov
>> Sent: martes, 07 de mayo de 2013 19:12
>> To: users at 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
>


Posted on the users mailing list.