PLUGIN-DEV: Checking for numbers

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

PLUGIN-DEV: Checking for numbers

Andrew Moschou
Hi all,

To test whether a thing x is a number, I wrote the following:

if(not(IsObject(x))) // THEREFORE IS NUMBER OR (LENGTH >= 0) STRING
{
    if(x = (x + 0)) // THEREFORE IS NUMBER OR CHARACTER (LENGTH = 1 STRING)
    {
        if(x != Asc(x)) // x IS A CHARACTER IF AND ONLY IF x IS ITS OWN UNICODE CODE POINT
        {               // THEREFORE x IS OTHERWISE A NUMBER
            if(x = Round(x))
            {
                return 1;
            }
            else
            {
                return 2;
            }
        }
    }
}
return 0;

0: not a number, 1: an integer, 2: a non integer number.

and then afterwards discovered Bob Zawalich already wrote a similar method in utils. Mine is simpler and therefore faster probably. I'm wondering if anybody can think of any situation where they would produce different results, I haven't found any. But my method abuses the Asc() method, which might be a bad thing...

Andrew

Reply | Threaded
Open this post in threaded view
|

PLUGIN-DEV: Re: Checking for numbers

Andrew Moschou
(Please ignore this message. I obviously did rather poor testing: it's not working. I might come back later if I fix it.)

2009/11/24 Andrew Moschou <[hidden email]>
Hi all,

To test whether a thing x is a number, I wrote the following:

if(not(IsObject(x))) // THEREFORE IS NUMBER OR (LENGTH >= 0) STRING
{
    if(x = (x + 0)) // THEREFORE IS NUMBER OR CHARACTER (LENGTH = 1 STRING)
    {
        if(x != Asc(x)) // x IS A CHARACTER IF AND ONLY IF x IS ITS OWN UNICODE CODE POINT
        {               // THEREFORE x IS OTHERWISE A NUMBER
            if(x = Round(x))
            {
                return 1;
            }
            else
            {
                return 2;
            }
        }
    }
}
return 0;

0: not a number, 1: an integer, 2: a non integer number.

and then afterwards discovered Bob Zawalich already wrote a similar method in utils. Mine is simpler and therefore faster probably. I'm wondering if anybody can think of any situation where they would produce different results, I haven't found any. But my method abuses the Asc() method, which might be a bad thing...

Andrew


Reply | Threaded
Open this post in threaded view
|

PLUGIN-DEV: Test is the list working?

Bob Zawalich
In reply to this post by Andrew Moschou

this is just a test…

Reply | Threaded
Open this post in threaded view
|

Re: PLUGIN-DEV: Test is the list working?

musictranscriber
Verifying receipt 

Regards,
The Music Transcriber
Roman Molino Dunn
http://www.themusictranscriber.com
http://www.themusictranscriber.com/plugin-store
610-392-4807

--- On Tue, 12/8/09, Bob Zawalich <[hidden email]> wrote:

From: Bob Zawalich <[hidden email]>
Subject: PLUGIN-DEV: Test is the list working?
To: [hidden email]
Date: Tuesday, December 8, 2009, 12:54 PM

this is just a test…


Reply | Threaded
Open this post in threaded view
|

Re: PLUGIN-DEV: Test is the list working?

Andrew Moschou
In reply to this post by Bob Zawalich
Success.

2009/12/9 Bob Zawalich <[hidden email]>

this is just a test…


Reply | Threaded
Open this post in threaded view
|

RE: PLUGIN-DEV: Test is the list working?

Dubravko Pajalic
In reply to this post by Bob Zawalich

ok

 

From: Majordomo Pseudo User [mailto:[hidden email]] On Behalf Of Bob Zawalich
Sent: Tuesday, December 08, 2009 9:54 AM
To: [hidden email]
Subject: PLUGIN-DEV: Test is the list working?

 

this is just a test…

Reply | Threaded
Open this post in threaded view
|

Re: PLUGIN-DEV: Test is the list working?

Louis Sumberg
In reply to this post by Bob Zawalich
I got it too.