[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

NaN return

Josselin

3/31/2007 2:31:00 PM

I am using a method 'distance_to' from a lib returning a distance in
Float type based on latitude/longitude

@ proposals.each do | proposal |
cd = proposal.distance_to(current_city)
@d = cd if (@d <=> cd) > 0
end

a problem arise when the proposal latitude/longitude are equivalent to
current_city latitude/longitude
in this case it returns NaN (and not 0.0.. don't know why....)
if I don't modify the lib script, how I can get bypass this results
(obviously I don't care about 0.0 distance)

something like..
cd = proposal.distance_to(current_city) != NaN ?
proposal.distance_to(current_city) : 0.0


5 Answers

Luis Parravicini

3/31/2007 2:44:00 PM

0

On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
> something like..
> cd = proposal.distance_to(current_city) != NaN ?
> proposal.distance_to(current_city) : 0.0

Float has a 'nan?' method
(http://www.ruby-doc.org/core/classes/Float.ht...).

Josselin

3/31/2007 3:10:00 PM

0

On 2007-03-31 16:43:58 +0200, "Luis Parravicini" <lparravi@gmail.com> said:

> On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
>> something like..
>> cd = proposal.distance_to(current_city) != NaN ?
>> proposal.distance_to(current_city) : 0.0
>
> Float has a 'nan?' method
> (http://www.ruby-doc.org/core/classes/Float.ht...).

thanks, I got it to test and replace cd : cd = 0.0 if cd.nan?

Float comparison is quite strange :
cd = 0.0
=> 0.0

irb(main):010:0> d = 0.197314075476553
=> 0.197314075476553

irb(main):011:0> (cd <=> d) > 0
=> false

BUT .....

irb(main):006:0> cd = 0.693524996891893
=> 0.693524996891893

irb(main):007:0> d = 0.197314075476553
=> 0.197314075476553

irb(main):008:0> (cd <=> d) > 0
=> true

so 0.693524996891893 seems to be greater than 0.197314075476553 ????

Luis Parravicini

3/31/2007 3:38:00 PM

0

On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
> so 0.693524996891893 seems to be greater than 0.197314075476553 ????

0.693524996891893 IS greater than 0.197314075476553 !!

Husein Choroomi

3/31/2007 4:05:00 PM

0

> so 0.693524996891893 seems to be greater than 0.197314075476553 ????

becasue 0.6 is greater than 0.1 !


On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
> On 2007-03-31 16:43:58 +0200, "Luis Parravicini" <lparravi@gmail.com> said:
>
> > On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
> >> something like..
> >> cd = proposal.distance_to(current_city) != NaN ?
> >> proposal.distance_to(current_city) : 0.0
> >
> > Float has a 'nan?' method
> > (http://www.ruby-doc.org/core/classes/Float.ht...).
>
> thanks, I got it to test and replace cd : cd = 0.0 if cd.nan?
>
> Float comparison is quite strange :
> cd = 0.0
> => 0.0
>
> irb(main):010:0> d = 0.197314075476553
> => 0.197314075476553
>
> irb(main):011:0> (cd <=> d) > 0
> => false
>
> BUT .....
>
> irb(main):006:0> cd = 0.693524996891893
> => 0.693524996891893
>
> irb(main):007:0> d = 0.197314075476553
> => 0.197314075476553
>
> irb(main):008:0> (cd <=> d) > 0
> => true
>
> so 0.693524996891893 seems to be greater than 0.197314075476553 ????
>
>
>


--
Husein Choroomi,
CEO, CTO
Yucca Intelligence Development
http://www.Y...

We make the web a better place!

Josselin

4/10/2007 12:07:00 PM

0

On 2007-03-31 17:38:11 +0200, "Luis Parravicini" <lparravi@gmail.com> said:

> On 3/31/07, Josselin <josselin@wanadoo.fr> wrote:
>> so 0.693524996891893 seems to be greater than 0.197314075476553 ????
>
> 0.693524996891893 IS greater than 0.197314075476553 !!

As I discover it few times after my post, I spent sometime away in a
ruby-church requiring forgiveness for my silly question... I also
bought new glasses ;-))) before coming back crawling on the ground and
raising my hands on the keyboard

thanks ;-)))

joss