NaN return

J

Josselin

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
 
J

Josselin


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 ????
 
H

Husein Choroomi

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

becasue 0.6 is greater than 0.1 !


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.YuccaHQ.com

We make the web a better place!
 
J

Josselin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top