Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

How many weeks are there in a light year?


devel / comp.lang.mumps / Checking whether a string is numeric

SubjectAuthor
* Checking whether a string is numericK.S. Bhaskar
+* Re: Checking whether a string is numericmpepper%...@gtempaccount.com
|+- Re: Checking whether a string is numericed de moel
|+- Re: Checking whether a string is numericRod Dorman
|`* Re: Checking whether a string is numericK.S. Bhaskar
| `* Re: Checking whether a string is numericed de moel
|  `* Re: Checking whether a string is numericK.S. Bhaskar
|   `- Re: Checking whether a string is numericK.S. Bhaskar
`* Re: Checking whether a string is numericretired developer
 `* Re: Checking whether a string is numericK.S. Bhaskar
  `- Re: Checking whether a string is numericretired developer

1
Checking whether a string is numeric

<cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=156&group=comp.lang.mumps#156

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a37:ea0c:: with SMTP id t12mr129899qkj.509.1631135333573;
Wed, 08 Sep 2021 14:08:53 -0700 (PDT)
X-Received: by 2002:aca:b6d5:: with SMTP id g204mr3821692oif.29.1631135333242;
Wed, 08 Sep 2021 14:08:53 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 8 Sep 2021 14:08:52 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=71.162.243.192; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 71.162.243.192
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
Subject: Checking whether a string is numeric
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Wed, 08 Sep 2021 21:08:53 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 8
 by: K.S. Bhaskar - Wed, 8 Sep 2021 21:08 UTC

I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.

What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.

Regards
– Bhaskar

Re: Checking whether a string is numeric

<84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=157&group=comp.lang.mumps#157

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ad4:5541:: with SMTP id v1mr321054qvy.49.1631148876313;
Wed, 08 Sep 2021 17:54:36 -0700 (PDT)
X-Received: by 2002:a9d:694c:: with SMTP id p12mr249068oto.182.1631148875987;
Wed, 08 Sep 2021 17:54:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Wed, 8 Sep 2021 17:54:35 -0700 (PDT)
In-Reply-To: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:6c40:4c00:75f2:15ec:53e2:3301:624a;
posting-account=ct7RVQoAAAB29s0HZQxoV0fWnKf6dw5q
NNTP-Posting-Host: 2600:6c40:4c00:75f2:15ec:53e2:3301:624a
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: mpepper%ieee.org@gtempaccount.com (mpepper%...@gtempaccount.com)
Injection-Date: Thu, 09 Sep 2021 00:54:36 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 19
 by: mpepper%...@gtempacc - Thu, 9 Sep 2021 00:54 UTC

On Wednesday, September 8, 2021 at 4:08:54 PM UTC-5, K.S. Bhaskar wrote:
> I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.
>
> What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.
>
> Regards
> – Bhaskar

It depends, so I'll ask the question one asks of a newbie, "what are you trying to do?"

The logical comparison, +x=x is a simple way to determine if x is in canonical form, but that's not what you asked.
In a former lifetime, I worked on a non-standard MUMPS which had a number-test function that was true if the string-to-number conversion made it to the end of the string before terminating. I think this is the function you want, but I know of no equivalent in standard M.

Re: Checking whether a string is numeric

<903f00e8-d084-4cf2-8cf6-4e56247d4550n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=159&group=comp.lang.mumps#159

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ae9:e502:: with SMTP id w2mr2780537qkf.200.1631195794006;
Thu, 09 Sep 2021 06:56:34 -0700 (PDT)
X-Received: by 2002:a54:4513:: with SMTP id l19mr2166257oil.143.1631195793757;
Thu, 09 Sep 2021 06:56:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 9 Sep 2021 06:56:30 -0700 (PDT)
In-Reply-To: <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com> <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <903f00e8-d084-4cf2-8cf6-4e56247d4550n@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Thu, 09 Sep 2021 13:56:33 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 1
 by: ed de moel - Thu, 9 Sep 2021 13:56 UTC

I don't want to turn this into a programming contest, but I have seen many attempts at addressing this issue, and most of them worked well for the situation where they were used.
One warning though, +"1E100" may result in a "numeric overflow" error, so you probably don't just want to know whether the value of a string qualifies as a "number", but also whether it is a number that is "usable" in your implementation.

Re: Checking whether a string is numeric

<shdj8n$1ns$1@reader1.panix.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=160&group=comp.lang.mumps#160

  copy link   Newsgroups: comp.lang.mumps
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: rodd@panix.com (Rod Dorman)
Newsgroups: comp.lang.mumps
Subject: Re: Checking whether a string is numeric
Date: Thu, 9 Sep 2021 18:20:07 -0000 (UTC)
Organization: Public Access Networks Corp.
Message-ID: <shdj8n$1ns$1@reader1.panix.com>
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com> <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
Injection-Date: Thu, 9 Sep 2021 18:20:07 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="1788"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
 by: Rod Dorman - Thu, 9 Sep 2021 18:20 UTC

In article <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>,
mpepper%...@gtempaccount.com <mpepper%ieee.org@gtempaccount.com> wrote:
> ...
>The logical comparison, +x=x is a simple way to determine if x is in
>canonical form, but that's not what you asked.

Even that has issues, its fine for what a typical user might enter but
not so good when theres an exponent.

The strings 2E3 and 2000 are both canonical and have the same numeric
value but testing 2E3 with +x=x fails

--
-- Rod --
rodd(at)polylogics(dot)com

Re: Checking whether a string is numeric

<d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=161&group=comp.lang.mumps#161

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ac8:58d0:: with SMTP id u16mr4423568qta.189.1631213824926;
Thu, 09 Sep 2021 11:57:04 -0700 (PDT)
X-Received: by 2002:a9d:630e:: with SMTP id q14mr1168691otk.316.1631213824451;
Thu, 09 Sep 2021 11:57:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 9 Sep 2021 11:57:04 -0700 (PDT)
In-Reply-To: <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.162.243.192; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 71.162.243.192
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com> <84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Thu, 09 Sep 2021 18:57:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 32
 by: K.S. Bhaskar - Thu, 9 Sep 2021 18:57 UTC

On Wednesday, September 8, 2021 at 8:54:37 PM UTC-4, mpepper%...@gtempaccount.com wrote:
> On Wednesday, September 8, 2021 at 4:08:54 PM UTC-5, K.S. Bhaskar wrote:
> > I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.
> >
> > What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.
> >
> > Regards
> > – Bhaskar
> It depends, so I'll ask the question one asks of a newbie, "what are you trying to do?"
>
> The logical comparison, +x=x is a simple way to determine if x is in canonical form, but that's not what you asked.
> In a former lifetime, I worked on a non-standard MUMPS which had a number-test function that was true if the string-to-number conversion made it to the end of the string before terminating. I think this is the function you want, but I know of no equivalent in standard M.

A fair question, Maury. I am trying to write an M expression where a canonical number is recognized as a canonical number. The best solution I have been able to come up with, assuming x is the string, is: x?1(1"",1"+",1"-")1(1".",1"").N1(1"E",1"E-",1"").N

To answer Ed's question, if the number is outside the range where the implementation can handle it, that's a different issue

Regards
– Bhaskar

Re: Checking whether a string is numeric

<96163287-4c4a-450b-a3a6-450ba5cc759bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=162&group=comp.lang.mumps#162

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:620a:2914:: with SMTP id m20mr4361414qkp.497.1631214262741;
Thu, 09 Sep 2021 12:04:22 -0700 (PDT)
X-Received: by 2002:a05:6830:2473:: with SMTP id x51mr1225178otr.34.1631214262497;
Thu, 09 Sep 2021 12:04:22 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 9 Sep 2021 12:04:22 -0700 (PDT)
In-Reply-To: <d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.174.62.16; posting-account=j7lJmQoAAADTx0Apfk15DZ7D0qlYy4zv
NNTP-Posting-Host: 71.174.62.16
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
<84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com> <d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <96163287-4c4a-450b-a3a6-450ba5cc759bn@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: eddemoel@gmail.com (ed de moel)
Injection-Date: Thu, 09 Sep 2021 19:04:22 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 1
 by: ed de moel - Thu, 9 Sep 2021 19:04 UTC

1E+2 should be OK too, so I'd suggest:
x?.1(1"+",1"-").N.1".".N.1(1"E"1.N,1"E-"1.N,1"E+"1.N)

Re: Checking whether a string is numeric

<7fa6c5c9-02ee-4848-895b-6dfedf2db7d3n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=163&group=comp.lang.mumps#163

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:622a:170a:: with SMTP id h10mr4674531qtk.327.1631219736451;
Thu, 09 Sep 2021 13:35:36 -0700 (PDT)
X-Received: by 2002:a05:6808:4d5:: with SMTP id a21mr1338592oie.34.1631219736100;
Thu, 09 Sep 2021 13:35:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 9 Sep 2021 13:35:35 -0700 (PDT)
In-Reply-To: <96163287-4c4a-450b-a3a6-450ba5cc759bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.162.243.192; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 71.162.243.192
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
<84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com> <d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>
<96163287-4c4a-450b-a3a6-450ba5cc759bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7fa6c5c9-02ee-4848-895b-6dfedf2db7d3n@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Thu, 09 Sep 2021 20:35:36 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 7
 by: K.S. Bhaskar - Thu, 9 Sep 2021 20:35 UTC

On Thursday, September 9, 2021 at 3:04:23 PM UTC-4, ed de moel wrote:
> 1E+2 should be OK too, so I'd suggest:
> x?.1(1"+",1"-").N.1".".N.1(1"E"1.N,1"E-"1.N,1"E+"1.N)

Thanks Ed. You are much less of a MUMPS newbie than I am!

Regards
– Bhaskar

Re: Checking whether a string is numeric

<00febb32-0c60-44f3-a859-77573a5f4754n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=164&group=comp.lang.mumps#164

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:a05:622a:11d0:: with SMTP id n16mr4806045qtk.297.1631222563951;
Thu, 09 Sep 2021 14:22:43 -0700 (PDT)
X-Received: by 2002:a9d:8f4:: with SMTP id 107mr1781480otf.248.1631222563614;
Thu, 09 Sep 2021 14:22:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Thu, 9 Sep 2021 14:22:43 -0700 (PDT)
In-Reply-To: <7fa6c5c9-02ee-4848-895b-6dfedf2db7d3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=71.162.243.192; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 71.162.243.192
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
<84a8d0f5-0e76-46ea-8a5e-2772cd611116n@googlegroups.com> <d0be08ee-2136-48fb-b9e9-69c2bf01c1bdn@googlegroups.com>
<96163287-4c4a-450b-a3a6-450ba5cc759bn@googlegroups.com> <7fa6c5c9-02ee-4848-895b-6dfedf2db7d3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <00febb32-0c60-44f3-a859-77573a5f4754n@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Thu, 09 Sep 2021 21:22:43 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 12
 by: K.S. Bhaskar - Thu, 9 Sep 2021 21:22 UTC

On Thursday, September 9, 2021 at 4:35:37 PM UTC-4, K.S. Bhaskar wrote:
> On Thursday, September 9, 2021 at 3:04:23 PM UTC-4, ed de moel wrote:
> > 1E+2 should be OK too, so I'd suggest:
> > x?.1(1"+",1"-").N.1".".N.1(1"E"1.N,1"E-"1.N,1"E+"1.N)
> Thanks Ed. You are much less of a MUMPS newbie than I am!
>
> Regards
> – Bhaskar

In retrospect, $char(0)]]x is probably the simplest test.

Regards
– Bhaskar

Re: Checking whether a string is numeric

<ipvq9gFrdniU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=165&group=comp.lang.mumps#165

  copy link   Newsgroups: comp.lang.mumps
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: retired.developer@protonmail.com (retired developer)
Newsgroups: comp.lang.mumps
Subject: Re: Checking whether a string is numeric
Date: Fri, 10 Sep 2021 03:21:52 +0200
Lines: 38
Message-ID: <ipvq9gFrdniU1@mid.individual.net>
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net N6hId50gjC+ajQKvYqGJ4wI4AENjyXbG/9eGatwvg42jB8wrdh
Cancel-Lock: sha1:DQWHfhsBBF3ptEeAZhgbBEtoFDo=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
Content-Language: en-US
 by: retired developer - Fri, 10 Sep 2021 01:21 UTC

On 08.09.21 23:08, K.S. Bhaskar wrote:
> I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.
>
> What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.

In addition to what others already wrote, you have to clarify the
"string is a number" definition:

- do you consider a string like "00123" or "123.4500" as numbers?
- do you consider a string like "-12" or "---123" or "-+-12" as numbers?

I would say, for a "string" to be a number:

- the string must contain at least one digit
- a period (if present) must be followed by a digit
- during the string to number conversion, all the characters
of that string must be consumed as part of the resulting number

For example:
"123.40" is a number
"123.4X" is not a number, "x" wasn't used to build the value 123.4
"123.,45" is not a number, "," and the digits 4 and 5 were not used
"+-+087.90" is a number
"12." is (not?) a number (a "." should be followed by a digit - or not?)

Also, in US, ".34" is the canonical form for european "0.34". Some 30-40
years ago, I worked with a MUMPS implementation where +".34" returned 0
because of the missing leading zero...

Regards
Julius

--
An old Windows has old security holes.
A new Windows has new security holes.
Another OS has other security holes.
For safety you must care yourself.

Re: Checking whether a string is numeric

<5ea612e7-a6ce-4f7d-84dd-560946573a42n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=166&group=comp.lang.mumps#166

  copy link   Newsgroups: comp.lang.mumps
X-Received: by 2002:ad4:5489:: with SMTP id q9mr8397564qvy.14.1631284157100;
Fri, 10 Sep 2021 07:29:17 -0700 (PDT)
X-Received: by 2002:a54:4419:: with SMTP id k25mr4548750oiw.32.1631284156745;
Fri, 10 Sep 2021 07:29:16 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.mumps
Date: Fri, 10 Sep 2021 07:29:16 -0700 (PDT)
In-Reply-To: <ipvq9gFrdniU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=108.52.84.50; posting-account=zTPg1AoAAABx_LtAQ3dW6FBnU1dwmSvl
NNTP-Posting-Host: 108.52.84.50
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com> <ipvq9gFrdniU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5ea612e7-a6ce-4f7d-84dd-560946573a42n@googlegroups.com>
Subject: Re: Checking whether a string is numeric
From: ksbhaskar@gmail.com (K.S. Bhaskar)
Injection-Date: Fri, 10 Sep 2021 14:29:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 76
 by: K.S. Bhaskar - Fri, 10 Sep 2021 14:29 UTC

On Thursday, September 9, 2021 at 9:21:55 PM UTC-4, retired developer wrote:
> On 08.09.21 23:08, K.S. Bhaskar wrote:
> > I confess that I am a MUMPS newbie, because it has only been something over 26 years since I wrote my first M program.
> >
> > What is the "correct" way to check whether or not a string is a number? 1E3, 1000, 1E0, and 1E-3 should be identified as numbers, but 1-2E3 should be identified as not a number.
> In addition to what others already wrote, you have to clarify the
> "string is a number" definition:
>
> - do you consider a string like "00123" or "123.4500" as numbers?
> - do you consider a string like "-12" or "---123" or "-+-12" as numbers?
>
> I would say, for a "string" to be a number:
>
> - the string must contain at least one digit
> - a period (if present) must be followed by a digit
> - during the string to number conversion, all the characters
> of that string must be consumed as part of the resulting number
>
> For example:
> "123.40" is a number
> "123.4X" is not a number, "x" wasn't used to build the value 123.4
> "123.,45" is not a number, "," and the digits 4 and 5 were not used
> "+-+087.90" is a number
> "12." is (not?) a number (a "." should be followed by a digit - or not?)
>
> Also, in US, ".34" is the canonical form for european "0.34". Some 30-40
> years ago, I worked with a MUMPS implementation where +".34" returned 0
> because of the missing leading zero...
>
>
> Regards
> Julius
>
> --
> An old Windows has old security holes.
> A new Windows has new security holes.
> Another OS has other security holes.
> For safety you must care yourself.

Thanks for the comments. I wanted to identify M canonical numbers (so, "+-+0.87.90" is an expression that evaluates to a number, but is not a number). In that regard at least, with YottaDB:

YDB>set x="123.40" write $char(0)]]x
0 YDB>set x="123.4" write $char(0)]]x
1 YDB>set x="123,45" write $char(0)]]x
0 YDB>set x="+-+087.90" write $char(0)]]x
0 YDB>set x="+-+087.9" write $char(0)]]x
0 YDB>set x="12." write $char(0)]]x
0 YDB>set x="12" write $char(0)]]x
1 YDB>set x=".34" write $char(0)]]x
1 YDB>set x="0.34" write $char(0)]]x
0 YDB>set x="-12" write $char(0)]]x
1 YDB>set x="---123" write $char(0)]]x
0 YDB>

Regards
– Bhaskar

Re: Checking whether a string is numeric

<iq255vFariaU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=167&group=comp.lang.mumps#167

  copy link   Newsgroups: comp.lang.mumps
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: retired.developer@protonmail.com (retired developer)
Newsgroups: comp.lang.mumps
Subject: Re: Checking whether a string is numeric
Date: Sat, 11 Sep 2021 00:39:59 +0200
Lines: 27
Message-ID: <iq255vFariaU1@mid.individual.net>
References: <cfe6275a-1647-42d1-8be3-c032b9ca9be7n@googlegroups.com>
<ipvq9gFrdniU1@mid.individual.net>
<5ea612e7-a6ce-4f7d-84dd-560946573a42n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net oARc4W3CLDZSxTRJ0dNNYAigXCiHeAkcO5Nk/wTcX3o7h1OGR0
Cancel-Lock: sha1:8URBCAFM4HQ/TRU2zDshm7qCFmg=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <5ea612e7-a6ce-4f7d-84dd-560946573a42n@googlegroups.com>
Content-Language: en-US
 by: retired developer - Fri, 10 Sep 2021 22:39 UTC

On 10.09.21 16:29, K.S. Bhaskar wrote:

> Thanks for the comments. I wanted to identify M canonical numbers (so, "+-+0.87.90" is an expression that evaluates to a number, but is not a number).

OK, you are talking about "canonical numbers". I was misled by your
original question:
>>> What is the "correct" way to check whether or not a string is a
number?

and thought, you want check an user input or something like that. Hence
my example, "123.40" is a number but "123.4xy" is not.

Probably the correct question should be "What is the "correct" way to
check whether or not a string is a canonical number?
-----------------------------^^^^^^^^^^^^^^^^

But never mind, we are there to clarify things.

Rehards
Julius

--
An old Windows has old security holes.
A new Windows has new security holes.
Another OS has other security holes.
For safety you must care yourself.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor