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

Home » Public Forums » archive » where function not finding value
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: where function not finding value [message #90571 is a reply to message #90570] Tue, 10 March 2015 19:34 Go to previous messageGo to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Tuesday, March 10, 2015 at 2:19:16 PM UTC-6, Jeff B wrote:
> On Tuesday, March 10, 2015 at 3:15:18 PM UTC-5, Jahvasc wrote:
>> Hi, Chris, thank you for your answer. But it was to avoid this floating point problems that I'm using the intervals. Besides, why when I write down the interval (mass gt 0.04 and mass le 0.05) I got the the right answer?
>
> Unfortunately you're not quite avoiding those issues. For instance, analogous to what you're doing try this
>
> IDL> print, 0.05 le 4.0*0.01+0.01
> 0
>
> IDL> print, 0.05 le 0.05
> 1
>
> The first example *should* return 1 in a perfect world, but once you do mathematical operations (such as the multiplication and addition) you will introduce floating point arithmetic issues.

One way to reduce (but not eliminate) these types of issues is to use double precision for all calculations:

IDL> print, 0.05d le 4*0.01d + 0.01d
1

Again, I can't stress enough that this is a problem with all languages. For example, in Python, if we use 32-bit floating-point numbers:

>>> import numpy as np
>>> f = np.float32
>>> f(0.05) <= 4*f(0.01) + f(0.01)
False

Cheers,
Chris
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: License Manager help
Next Topic: Map_proj_forward.pro

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

Current Time: Sat Oct 11 07:17:29 PDT 2025

Total time taken to generate the page: 0.71807 seconds