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 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: fractional part of a number [message #7929] Fri, 24 January 1997 00:00
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
Re: fractional part of a number [message #7935 is a reply to message #7929] Thu, 23 January 1997 00:00 Go to previous message
Andy Loughe is currently offline  Andy Loughe
Messages: 174
Registered: November 1995
Senior Member
Mirko Vukovic wrote:
>
> How does one get the fractional part of a number? Could not find
> anything in the manual.


number = 5.89
frac_number = number - fix(number)

Is one way to do it.

--
Andrew F. Loughe |
afl@cdc.noaa.gov
University of Colorado, CIRES Box 449 |
http://cdc.noaa.gov/~afl
Boulder, CO 80309-0449 | phn:(303)492-0707
fax:(303)497-7013
------------------------------------------------------------ ---------------
"I do not feel obliged to believe that the same God who has endowed us
with
sense, reason, and intellect has intended us to forego their use."
-Galileo
Re: fractional part of a number [message #7937 is a reply to message #7935] Thu, 23 January 1997 00:00 Go to previous message
Phil Williams is currently offline  Phil Williams
Messages: 78
Registered: April 1996
Member
Mirko Vukovic wrote:
>
> How does one get the fractional part of a number? Could not find
> anything in the manual.
>

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

Good luck,
Phil
--
/*********************************************************** ********/
Phil Williams, Ph.D.
Research Instructor
Children's Hospital Medical Center "One man gathers what
Imaging Research Center another man spills..."
3333 Burnet Ave. -The Grateful Dead
Cincinnati, OH 45229
email: williams@irc.chmcc.org
URL: http://scuttle.chmcc.org/~williams/
/*********************************************************** ********/
Re: fractional part of a number [message #7938 is a reply to message #7935] Thu, 23 January 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
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. :-)

David

-----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
2642 Bradbury Court, Fort Collins, CO 80521
Phone: 970-221-0438 Fax: 970-221-4762
E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
-----------------------------------------------------------
  Switch to threaded view of this topic Create a new topic Submit Reply
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 11:21:29 PDT 2025

Total time taken to generate the page: 1.36204 seconds