read float in other base

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

read float in other base

Nicolas Cellier-3
i see i can enter a float with exponent in another base than 10,
but have a very minor question illustrated in this example:

    "this one is not zero - exponent is not interpreted in base 16"
    16r1.0e10 - (16 raisedTo: 16).

    "this one is zero - exponent is interpreted in base 10"
    16r1.0e10 - (16 raisedTo: 10).

    "this one would not execute (send r10 to 16r1.0e16)
    exponent cannot be expressed in base 16"
     16r1.0e16r10 - (16 raisedTo: 16)

As shown above, exponent is always interpreted in base 10. why ?
is it compatible with any other language convention ?
(note that exponent is forbidden in VW when base is not 10, so no clue from
this dialect...).


Reply | Threaded
Open this post in threaded view
|

Re: read float in other base

Nicolas Cellier-3

Still playing with Number readFrom: and printStringBase:,
I have something smelling like a bug, not a great one,
just some never used and never cleaned dusty corners of code...

    "this should be the maximum floating point value in IEEE 754 double
precision"
    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) printStringBase: 16.

"will print as 16r1.0e255"
    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1020';
        contents)) printStringBase: 16.

"will print as 16r2.0e255"

look at http://bugs.impara.de/view.php?id=3493 for further details

Nicolas


Reply | Threaded
Open this post in threaded view
|

Re: read float in other base

Nicolas Cellier-3

I have a correction for http://bugs.impara.de/view.php?id=3493,
(it is an overflow problem with these silent Infinity GRRR)
but bad luck, there is another bug in the same method:

    (Number readFrom: ((String new: 100) writeStream
        nextPutAll: '2r1.';
        next: 52 put: $1;
        nextPutAll: 'e1023';
        contents)) printStringBase: 2.

    "will answer 2r2.0e1024"

I wonder if the case can ever show in base 10 (the logical conditions tc1 and
tc2 in the code are too much for my brain at this late time).
In that case you would get letter A before decimal point sometimes...
I am quite sure sometimes means almost never (it would be corrected already),
but with some bad luck, it could hurt a poor guy printing Floats like me...
Anyone have a big SUnit related to Float that could be recycled on this print
method ?

 Nicolas


Reply | Threaded
Open this post in threaded view
|

Re: read float in other base

Wolfgang Helbig-2
In reply to this post by Nicolas Cellier-3
Hi Nicolas,

You wrote some expressions containing float literals with a radix prefix and an
exponent and wondered:

>As shown above, exponent is always interpreted in base 10. why ?
Because there is no need to express it in the base specified in
the radix prefix?

>is it compatible with any other language convention ?
Is it not compatible with any other language convention ?

>(note that exponent is forbidden in VW when base is not 10, so no clue from
>this dialect...).

But there is a clue from the Blue Book (p 20):
        "The exponent suffix includes the letter "e" followed by the exponent
        (expressed in decimal)."

Greetings
Wolfgang

--
Weniger, aber besser.