Re: Fraction>>asFloat (FloatingPoint Overflow)



Hi Howard,
Yes, i see two problems
1) ((1 bitShift: 10000)/3)asFloat should raise an overflow, note a zero
divide
2) your float won't be as precise as it could be
(i mean it likely won't be the closest float to the fraction)

See http://ncellier.ifrance.com/Dolphin_packages.html (via
http://www.dolphinmap.net/wiki/Goodies)

Nicolas

Howard Oh a e'crit :
A very precise but not a big fraction like:

(4941354647941236926152115130903637082561047305201416295417964660936672448910241499199436867464432378497521953013385156994196064073355718205444063842406844645633777822001794087786934643288359176347668049138450287177670914977920820153695869859050205437477052264104760638348351154610327758358316855246056228125726457933011243259488904319976931378470626978044536189271422830698827951298790996380571297736272436985642542223705097895166027/7128865274665093053166384155714272920668358861885893040452001991154324087581111499476444151913871586911717817019575256512980264067621009251465871004305131072686268143200196609974862745937188343705015434452523739745298963145674982128236956232823794011068809262317708861979540791247754558049326475737829923352751796735248042463638051137034331214781746850878453485678021888075373249921995672056932029099390891687487672697950931603520000)

will raises 'Floating point error: Overflow' error when #asFloat is
sent.



I kinda fixed

Fraction>>asFloat

^[numerator asFloat / denominator asFloat] on:
FloatingPointException
do: [:exception|
(exception printString
includesSubCollection: 'Floating point error: Overflow')
ifTrue: [ |fmax newN newD|
fmax := Float fmax asInteger.
newN := numerator.
newD := denominator.
[newN abs < fmax and: [newD abs < fmax]]

whileFalse: [ newN := newN // 2. newD := newD // 2 ].
(newN / newD) asFloat ]
ifFalse: [exception signal] ]



It is now evaluates;
... asFloat "0.69314743055982"


I a little scaled to modify Fraction.
Is there a potential problem in my solution?
Is there a safer way?

Have a good one
Howard

.



Relevant Pages

  • Re: css problem (float)
    ... element in the normal flow that establishes a new block formatting ... not overlap any floats in the same block formatting context as the ... cells, positioned things, things with overflow other than visible. ... float: right; ...
    (alt.html)
  • Re: IE6 overflow problem
    ... the paragraph element growing height to enclose the floated image. ... overflow does not work with IE6 to address the problem. ... But this will not work in your case because you have the float within ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: div/bg color issue.. ok, heres the deal....;)
    ... Background images with repeat-y pretending to be column backgrounds. ... Point is, the longer column is the float, ... leaving the right column div ... Because the container is overflow: hidden, it grows to the height of the ...
    (comp.infosystems.www.authoring.stylesheets)
  • Re: Avoiding Overflow
    ... this is incorrect as the multiply will be calculated first and ... > are done on the FPU, which uses 10-byte floating point storage internally. ... > result stored back to the float / double type that we were using. ... the overflow would not occur when using float / double. ...
    (microsoft.public.vc.language)