Test if value is numerical

  • Follow


Hi,

I am occasionally using this simple test:

type = $1 + 0 == $1 ? "numerical" : "not numerical"

I am just wondering: can there be cases where this test will fail ?

Thanks in advance, Hermann
0
Reply Hermann 1/20/2009 8:04:39 PM

Hermann Peifer escribi�:
> Hi,
> 
> I am occasionally using this simple test:
> 
> type = $1 + 0 == $1 ? "numerical" : "not numerical"
> 
> I am just wondering: can there be cases where this test will fail ?
> 

It depends on how you define "numerical". Values ouside the supported 
numerical range are considered "not numerical", even if they follow the 
grammar rules for numerical tokens. Example (32 bit platform):

1e308 - numerical
2e308 - not numerical

> Thanks in advance, Hermann

Regards.
-- 
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado
0
Reply Manuel 1/20/2009 9:36:50 PM


On Jan 20, 2:04=A0pm, Hermann Peifer <pei...@gmx.eu> wrote:
> Hi,
>
> I am occasionally using this simple test:
>
> type =3D $1 + 0 =3D=3D $1 ? "numerical" : "not numerical"
>
> I am just wondering: can there be cases where this test will fail ?
>
> Thanks in advance, Hermann

Is "1,000" numerical?

    Ed.
0
Reply Ed 1/20/2009 10:02:11 PM

Ed Morton wrote:
> On Jan 20, 2:04 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>> Hi,
>>
>> I am occasionally using this simple test:
>>
>> type = $1 + 0 == $1 ? "numerical" : "not numerical"
>>
>> I am just wondering: can there be cases where this test will fail ?
>>
>> Thanks in advance, Hermann
> 
> Is "1,000" numerical?
> 
>     Ed.

Not according to our business rules.

Hermann
0
Reply Hermann 1/20/2009 11:12:28 PM

On Wednesday 21 January 2009 00:12, Hermann Peifer wrote:

> Ed Morton wrote:
>> On Jan 20, 2:04 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>>> Hi,
>>>
>>> I am occasionally using this simple test:
>>>
>>> type = $1 + 0 == $1 ? "numerical" : "not numerical"
>>>
>>> I am just wondering: can there be cases where this test will fail ?
>>>
>>> Thanks in advance, Hermann
>> 
>> Is "1,000" numerical?
>> 
>>     Ed.
> 
> Not according to our business rules.

and neither according to awk grammr, AFAICT.
0
Reply pk 1/21/2009 9:18:34 AM

pk wrote:
> On Wednesday 21 January 2009 00:12, Hermann Peifer wrote:
> 
>> Ed Morton wrote:
>>> On Jan 20, 2:04 pm, Hermann Peifer <pei...@gmx.eu> wrote:
>>>> Hi,
>>>>
>>>> I am occasionally using this simple test:
>>>>
>>>> type = $1 + 0 == $1 ? "numerical" : "not numerical"
>>>>
>>>> I am just wondering: can there be cases where this test will fail ?
>>>>
>>>> Thanks in advance, Hermann
>>> Is "1,000" numerical?
>>>
>>>     Ed.
>> Not according to our business rules.
> 
> and neither according to awk grammr, AFAICT.

As far as I am aware: Gawk's grammar rules have changed over time. In the current version 3.1.6, the above test would only result in "numerical" if you would use the new option, --use-lc-numeric, and would be working with ... say: de_DE.UTF-8 locale settings.

See also: http://tinyurl.com/88zhy4

Hermann

0
Reply Hermann 1/21/2009 6:08:59 PM

5 Replies
184 Views

(page loaded in 0.057 seconds)

Similiar Articles:













7/15/2012 8:30:27 AM


Reply: