Re: What is the fastest way of getting the fraction part of a floating point number?




\\\o///annabee wrote:
På Thu, 2 Feb 2006 15:29:06 -0800 (PST), skrev Phil Carmody
<spamtrap@xxxxxxxxxx>:

<<<
What is the fastest way of getting the fraction part of a floating point
number?

So, if I have a float 10.3 what is the fastest way of getting a float
with
the value 0.3?


Add 2^0, subtract 2^0, what's the difference between what you now have
and your
original number?

Add 2^1, subtract 2^1, what's the difference ...
...
...

eventually, you will find the answer.

(hint - start at about 2^50 to save 50 iterations)


Phil "why don't they teach this stuff anymore" Carmody

Is it faster then 9 cycles?

I tried this :

fld D§fpu_test32
and D§fpu_test32_2 FractionFlag ;clears fraction bits
fld D§fpu_test32
fsubp ST1 ST0
fstp D§fpu_test32

9 cycles.


Assuming I've guessed the contents of "FractionFlag" correctly
(0xff800000), that basically subtracts the largest power of two smaller
than the input number from the input, which is not what the OP asked
about. For an input of 10.3, the OP wanted the result .3, not 2.3.


.



Relevant Pages

  • Re: What is the fastest way of getting the fraction part of a floating point number?
    ... What is the fastest way of getting the fraction part of a floating point ... if I have a float 10.3 what is the fastest way of getting a float with ... fld D§fpu_test32 ...
    (comp.lang.asm.x86)
  • [BUG][FIX] Float conversion #asFloat and #asTrueFraction
    ... There are several problems in Dolphin Float/Fraction conversion ... Float asTrueFraction does not handle denormalized number ... Large fractions asFloat do overflow ... Integer and Fraction #asFloat do not round to nearest Floating ...
    (comp.lang.smalltalk.dolphin)
  • Re: Rounnding Issue
    ... In the database, if the datatype is a float, it will not contain EXACTLY 20.45 because that value CANNOT be stored in a float. ... A float is a binary fraction and asking a binary fraction to store 20.45 is like asking a decimal fraction to store 1/3. ...
    (microsoft.public.sqlserver.programming)
  • Re: About floating number arithmetic
    ... The top n bits of this fraction will directly give you the relevant ... Store the reciprocal as an array of float resolution values: ... mantissa bits as a float and the next 53 bits as a double. ... Having these three bits plus the rounding mode allows you to generate ...
    (comp.lang.asm.x86)
  • Re: Using fractions instead of floats
    ... So the solution I think is using a fraction type/class, ... similar in Python, in which dividing two numbers gives you a fraction, ... instead of an integer or a float (decided for python ... The gmpy module has unlimited precision rationals. ...
    (comp.lang.python)