Hi, Object.isNumber() returns true on NaN. I don''t think that''s true.... NaN is Not a Number so it''s not a number... right? By the way, I''m using Prototype 1.6.0.2. Satoru --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
It depends on your perspective. "typeof NaN" returns
"number" in
JavaScript. NaN certainly doesn''t fit into any of the other buckets.
Others have suggested that NaN ought to make Object.isNumber return
false. But unless we have a compelling reason to do so, I think we
ought to make the function mirror "typeof" as much as possible. Doing
so is, in my opinion, less surprising.
Anyway, if anyone is bothered by this behavior, add something like
this to your standard library:
Object.isValidNumber = function(object) {
return typeof object === ''number'' && !isNaN(number)
&& number !=Infinity && number !== -Infinity;
};
Cheers,
Andrew
On Apr 11, 3:27 am, Satoru Moriwaki
<satorumoriw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> Object.isNumber() returns true on NaN. I don''t think
that''s true....
> NaN is Not a Number so it''s not a number... right?
>
> By the way, I''m using Prototype 1.6.0.2.
>
> Satoru
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Andrew, Thanks for your reply. I understood. I have no problem with your answer. I''ll extend Object with isValidNumber() method to use it instead :) Satoru On Apr 11, 6:18 pm, Andrew Dupont <goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org> wrote:> It depends on your perspective. "typeof NaN" returns "number" in > JavaScript. NaN certainly doesn''t fit into any of the other buckets. > > Others have suggested that NaN ought to make Object.isNumber return > false. But unless we have a compelling reason to do so, I think we > ought to make the function mirror "typeof" as much as possible. Doing > so is, in my opinion, less surprising. > > Anyway, if anyone is bothered by this behavior, add something like > this to your standard library: > > Object.isValidNumber = function(object) { > return typeof object === ''number'' && !isNaN(number) && number !=> Infinity && number !== -Infinity; > > }; > > Cheers, > Andrew > > On Apr 11, 3:27 am, Satoru Moriwaki <satorumoriw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > Object.isNumber() returns true on NaN. I don''t think that''s true.... > > NaN is Not a Number so it''s not a number... right? > > > By the way, I''m using Prototype 1.6.0.2. > > > Satoru--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s the beauty of JavaScript! Satoru Moriwaki wrote:> I''ll extend Object with isValidNumber() method to use it instead :)--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
That''s what isFinite() does, afaik : )
isFinite(5); // => true
isFinite(''foo''); // => false
isFinite(NaN); // => false
isFinite(Infinity); // => false
isFinite(-Infinity); // => false
- kangax
On Apr 11, 5:18 am, Andrew Dupont
<goo...-TiabPMV39B5K4mp1Ns0Z8Q@public.gmane.org>
wrote:> It depends on your perspective. "typeof NaN" returns
"number" in
> JavaScript. NaN certainly doesn''t fit into any of the other
buckets.
>
> Others have suggested that NaN ought to make Object.isNumber return
> false. But unless we have a compelling reason to do so, I think we
> ought to make the function mirror "typeof" as much as possible.
Doing
> so is, in my opinion, less surprising.
>
> Anyway, if anyone is bothered by this behavior, add something like
> this to your standard library:
>
> Object.isValidNumber = function(object) {
> return typeof object === ''number'' &&
!isNaN(number) && number !=> Infinity && number !==
-Infinity;
>
> };
>
> Cheers,
> Andrew
>
> On Apr 11, 3:27 am, Satoru Moriwaki
<satorumoriw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Hi,
>
> > Object.isNumber() returns true on NaN. I don''t think
that''s true....
> > NaN is Not a Number so it''s not a number... right?
>
> > By the way, I''m using Prototype 1.6.0.2.
>
> > Satoru
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- VB IsDate/IsNumber: Localisation does not work
- Installation of Rails without ''gem install rails''
- IEEE_754 logic
- How to check an input String is a number or not in ruby?
- ROBUSTNESS: x || y and x && y to give warning/error if length(x) != 1 or length(y) != 1