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 #41177] Mon, 27 September 2004 00:37 Go to previous message
Paolo Grigis is currently offline  Paolo Grigis
Messages: 171
Registered: December 2003
Senior Member
Well, IDL does give the right answer (modulo 0.1 of course!)
within the floating point precision limits...

print,(1. mod 0.1),format='(f20.15)'
0.099999986588955
print,abs((1. mod 0.1)-0.1) LT (machar()).eps
1

and of course 0.09999... is approximately equal 0.0000...
(modulo 0.1). So the question would be: why does it matter?
The whole point of taking the modulo is to have numbers near
0.1 being "close neighbours" to numbers near 0.0 anyway...

Paolo

Christopher Lee wrote:
> 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: Thu Oct 09 23:44:23 PDT 2025

Total time taken to generate the page: 0.79844 seconds