comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: fractional part of a number
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: fractional part of a number [message #7929] Fri, 24 January 1997 00:00 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
davidf@dfanning.com (David Fanning) writes:

> Mirko Vukovic writes:

>>> How does one get the fractional part of a number? Could not find
>>> anything in the manual.

> Then Phil Williams answers:
>
>> Do you mean this:
>> IDL> n = 5.5
>> IDL> print, n mod floor(n)
>> 0.500000

> And Andy Loughe follows this with:

>> number = 5.89
>> frac_number = number - fix(number)

> BUT, and here is the important question: which is FASTER!


> No, no, I was just kidding. I do love these kinds of questions, though. :-)

Actually, neither of these approaches is completely robust, because of their
different behaviors for negative numbers,

IDL> n = -5.5
IDL> print, n mod floor(n)
-5.50000
IDL> print, n - fix(n)
-0.500000

I think the correct way to do it is to combine the two approaches,

IDL> print, n - floor(n)
0.500000

That is, if you agree with me that the integer part of -5.5 is -6, and the
fractional part is +0.5. :^)

Bill Thompson
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Reading Multiple Image TIFFs
Next Topic: Re: idl and pv-wave (GUI differences?)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 15:12:53 PDT 2025

Total time taken to generate the page: 1.04137 seconds