NaN return

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

On 3/31/07, Josselin [email protected] wrote:

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

Float has a ‘nan?’ method
(class Float - RDoc Documentation).

On 2007-03-31 16:43:58 +0200, “Luis P.” [email protected]
said:

On 3/31/07, Josselin [email protected] wrote:

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

Float has a ‘nan?’ method
(class Float - RDoc Documentation).

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

On 3/31/07, Josselin [email protected] wrote:

so 0.693524996891893 seems to be greater than 0.197314075476553 ???

0.693524996891893 IS greater than 0.197314075476553 !!

On 2007-03-31 17:38:11 +0200, “Luis P.” [email protected]
said:

On 3/31/07, Josselin [email protected] 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

so 0.693524996891893 seems to be greater than 0.197314075476553 ???

becasue 0.6 is greater than 0.1 !

On 3/31/07, Josselin [email protected] wrote:

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

so 0.693524996891893 seems to be greater than 0.197314075476553 ???

Husein C.,
CEO, CTO
Yucca Intelligence Development

We make the web a better place!