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

Home » Public Forums » archive » Re: A bug in MOD ?
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: A bug in MOD ? [message #41192 is a reply to message #41182] Fri, 24 September 2004 10:06 Go to previous messageGo to previous message
Chris Lee is currently offline  Chris Lee
Messages: 101
Registered: August 2003
Senior Member
In article <cj1cqe$gut$1@canarie.caspur.it>, "sandrokan"
<mura@remove.ifsi.rm.cnr.it> wrote:


> I don't know much about libs, I only have IDl and another s/w: IDL>
> print, 1.0 mod 0.1
> 0.100000
> but:
>
>>> mod(1.0, 0.1)
> ans =
> 0
>>>

Hi,

Ah, matlab, wonderful matlab.I think Matlab uses arbitrary precision
math. where this answer is correct. I could be wrong of course.

The answer lies in the floating point representation of 1.0 and 0.1, or
any number. One of the numbers are really what they appear (not sure
which one) and the result is that ..

floor(1.0/0.1)=9
1.0 mod 0.1 = 0.1

;these may not work in any known language, but they do show what's
happening.

Calculating 0.8 mod 0.1, you get the correct answer, because
whatever representation error exists in 0.8 also exists in 0.1 .similarly
for 1.0 and 0.5|0.25|0.125 (powers of 2).

This is true of the IDL mod, the C++ fmod call (and probably the C
library fmodf call, as its used internallyin C++), the fortran mod function, the python
mod function, etc.

I'm not sure what the correct method would be. I can't really round a
value to zero when the value is comparable to the denominator in the
'mod' equation. It gets worse when I realize I've used 'mod' on a
floating point before, in FORTRAN code.

Chris.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Munich Adventures and other Coyote Stories
Next Topic: Integration of 2-D irregularly gridded data

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

Current Time: Sat Oct 11 08:12:23 PDT 2025

Total time taken to generate the page: 0.48436 seconds