Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

This screen intentionally left blank.


devel / comp.lang.awk / Re: Is it possible to convert strings to math operators?

SubjectAuthor
* Is it possible to convert strings to math operators?someone
+* Re: Is it possible to convert strings to math operators?Kenny McCormack
|`* Re: Is it possible to convert strings to math operators?someone
| `- Re: Is it possible to convert strings to math operators?Kenny McCormack
`* Re: Is it possible to convert strings to math operators?Ed Morton
 `* Re: Is it possible to convert strings to math operators?someone
  `- Re: Is it possible to convert strings to math operators?Kpop 2GM

1
Is it possible to convert strings to math operators?

<tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail
From: someone@invalid.invalid (someone)
Newsgroups: comp.lang.awk
Subject: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 08:02:31 -0700
Organization: Ministry of Madness
Message-ID: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Feb 2023 15:02:31 -0000 (UTC)
Injection-Info: nnrp.usenet.blueworldhosting.com;
logging-data="3840"; mail-complaints-to="usenet@blueworldhosting.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:H4KomcaDOZ2fyx8xFRy8xz9EPwE= sha256:Cne8NqzDOM1Cdkj+yz/DbhOrNzj+1JaUgzf5G8lYDWQ=
sha1:fFYXySZJs5MJqllgOiCY8tK+7ro= sha256:b4JfmAUPcnfcUPBVVtRAWNz2OQEeDHY8zrmQ67kcBuU=
Content-Language: en-US
 by: someone - Thu, 16 Feb 2023 15:02 UTC

I didn't see anything in the gawk(1) manpage for doing this but it seems
like it should be possible.

ex. oz to lb using old-school units(1) command:
--
$ units -1 oz lb
* 0.0625

# this works:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 * $3 " lb"}'
16 oz = 1 lb

# this does NOT work:
$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 $2 $3 " lb"}'
16 oz = 16*0.0625 lb

--

Is there a way to tell (g)awk to interpret strings like "*", "/", "+",
"-", etc. as actual math operators or do I need to create a series of
tests of $2 in the above example?

Re: Is it possible to convert strings to math operators?

<tsliir$3vb1l$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 15:36:59 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tsliir$3vb1l$1@news.xmission.com>
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
Injection-Date: Thu, 16 Feb 2023 15:36:59 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4172853"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 16 Feb 2023 15:36 UTC

In article <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>,
someone <someone@invalid.invalid> wrote:
>
>ex. oz to lb using old-school units(1) command:
>
>$ units -1 oz lb
> * 0.0625
>
># this works:
>$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 * $3 " lb"}'
>16 oz = 1 lb
>
># this does NOT work:
>$ echo "16 $(units -1 oz lb)" |awk '{print $1 " oz = " $1 $2 $3 " lb"}'
>16 oz = 16*0.0625 lb
>
>Is there a way to tell (g)awk to interpret strings like "*", "/", "+",
>"-", etc. as actual math operators

The short answer is "No". The slightly longer answer is "No, awk does not
have eval".

>or do I need to create a series of
>tests of $2 in the above example?

You could switch to Perl (which does have eval).

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Pearls

Re: Is it possible to convert strings to math operators?

<tsll3n$2drb$1@nnrp.usenet.blueworldhosting.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail
From: someone@invalid.invalid (someone)
Newsgroups: comp.lang.awk
Subject: Re: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 09:20:07 -0700
Organization: Ministry of Madness
Message-ID: <tsll3n$2drb$1@nnrp.usenet.blueworldhosting.com>
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
<tsliir$3vb1l$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Feb 2023 16:20:07 -0000 (UTC)
Injection-Info: nnrp.usenet.blueworldhosting.com;
logging-data="79723"; mail-complaints-to="usenet@blueworldhosting.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:RzO6EeveKYWK3TdZr8S3JKdultU= sha256:EjOUnHP6PQVNtY/OoNgGy1i08tW2OrzaNZFmUtsb/z8=
sha1:2HpSZLxwhIU08w2aauDR2NorqZ8= sha256:t+gPkpWs8AK310CB6L9lcyVUWnVwYS3DKpiAlpGWlCw=
Content-Language: en-US
In-Reply-To: <tsliir$3vb1l$1@news.xmission.com>
 by: someone - Thu, 16 Feb 2023 16:20 UTC

On 2/16/23 8:36 AM, Kenny McCormack wrote:
> The short answer is "No". The slightly longer answer is "No, awk does not
> have eval".

Ah okay thanks; guess I wasn't missing something in the docs after all.

I don't really have practical reason for needing an eval() function, was
just something I came across while trying other things.

Re: Is it possible to convert strings to math operators?

<tslmmc$3vdhv$1@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 16:47:08 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <tslmmc$3vdhv$1@news.xmission.com>
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com> <tsliir$3vb1l$1@news.xmission.com> <tsll3n$2drb$1@nnrp.usenet.blueworldhosting.com>
Injection-Date: Thu, 16 Feb 2023 16:47:08 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4175423"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 16 Feb 2023 16:47 UTC

In article <tsll3n$2drb$1@nnrp.usenet.blueworldhosting.com>,
someone <someone@invalid.invalid> wrote:
>On 2/16/23 8:36 AM, Kenny McCormack wrote:
>> The short answer is "No". The slightly longer answer is "No, awk does not
>> have eval".
>
>Ah okay thanks; guess I wasn't missing something in the docs after all.
>
>I don't really have practical reason for needing an eval() function, was
>just something I came across while trying other things.

Yes, I get it. Although I've often wished AWK did have eval capability,
I've never really wanted it enough for it to be a deal-breaker. So, you
learn to live without it.

Incidentally, I was once told by an AWK developer that the hard part about
implementing eval is if the thing you're eval'ing causes a new variable to
spring into existence.

--
Trump - the President for the rest of us.

https://www.youtube.com/watch?v=JSkUJKgdcoE

Re: Is it possible to convert strings to math operators?

<tslvek$3b56j$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mortonspam@gmail.com (Ed Morton)
Newsgroups: comp.lang.awk
Subject: Re: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 13:16:36 -0600
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <tslvek$3b56j$1@dont-email.me>
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Feb 2023 19:16:36 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f0248087edcf1711e81010b78fef45d6";
logging-data="3511507"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ea75fIwa8xLiLQuRy7G1l"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.7.2
Cancel-Lock: sha1:DH5nHNO5TwUOufGa+ypaJN9H02o=
X-Antivirus: Avast (VPS 230216-10, 2/16/2023), Outbound message
In-Reply-To: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
X-Antivirus-Status: Clean
Content-Language: en-US
 by: Ed Morton - Thu, 16 Feb 2023 19:16 UTC

On 2/16/2023 9:02 AM, someone wrote:
> I didn't see anything in the gawk(1) manpage for doing this but it seems
> like it should be possible.
>

It's not possible entirely within 1 call to awk but see
https://stackoverflow.com/a/54161251/1745001 for a (slow) workaround.

Ed.

Re: Is it possible to convert strings to math operators?

<tsmmlr$1t5d$1@nnrp.usenet.blueworldhosting.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!nnrp.usenet.blueworldhosting.com!.POSTED!not-for-mail
From: someone@invalid.invalid (someone)
Newsgroups: comp.lang.awk
Subject: Re: Is it possible to convert strings to math operators?
Date: Thu, 16 Feb 2023 18:52:59 -0700
Organization: Ministry of Madness
Message-ID: <tsmmlr$1t5d$1@nnrp.usenet.blueworldhosting.com>
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
<tslvek$3b56j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 17 Feb 2023 01:52:59 -0000 (UTC)
Injection-Info: nnrp.usenet.blueworldhosting.com;
logging-data="62637"; mail-complaints-to="usenet@blueworldhosting.com"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.6.0
Cancel-Lock: sha1:T9WVffFomqYWXqbPxy8jJ3QYSuQ= sha256:uJiZ8sWR1+kpW/3LeEB1uPga8R4gnhv2JoI2cmSbjN0=
sha1:0uUJ7ktm8VvmAqIzDQizxtosmxw= sha256:umisWt7Cm1xYHoeaNvVi1UNZmr4r/H7zViGCRtd8MXU=
Content-Language: en-US
In-Reply-To: <tslvek$3b56j$1@dont-email.me>
 by: someone - Fri, 17 Feb 2023 01:52 UTC

On 2/16/23 12:16 PM, Ed Morton wrote:
> On 2/16/2023 9:02 AM, someone wrote:
>> I didn't see anything in the gawk(1) manpage for doing this but it
>> seems like it should be possible.
>>
>
> It's not possible entirely within 1 call to awk but see
> https://stackoverflow.com/a/54161251/1745001 for a (slow) workaround.
>
>     Ed.

Interesting -- I had been thinking about this earlier actually but I'm
not yet proficient enough to write functions like this. Bookmarked!

Re: Is it possible to convert strings to math operators?

<cd8b9ac4-51d1-4293-97aa-214c8a25c4e8n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a37:4553:0:b0:71f:b8e9:362c with SMTP id s80-20020a374553000000b0071fb8e9362cmr5429693qka.8.1678308284619;
Wed, 08 Mar 2023 12:44:44 -0800 (PST)
X-Received: by 2002:a05:6830:3094:b0:693:c521:f86d with SMTP id
g20-20020a056830309400b00693c521f86dmr6724840ots.6.1678308284355; Wed, 08 Mar
2023 12:44:44 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Wed, 8 Mar 2023 12:44:44 -0800 (PST)
In-Reply-To: <tsmmlr$1t5d$1@nnrp.usenet.blueworldhosting.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2603:7000:3c3d:41c0:41c4:8bbb:2ef0:e48a;
posting-account=n74spgoAAAAZZyBGGjbj9G0N4Q659lEi
NNTP-Posting-Host: 2603:7000:3c3d:41c0:41c4:8bbb:2ef0:e48a
References: <tslgi7$3o0$1@nnrp.usenet.blueworldhosting.com>
<tslvek$3b56j$1@dont-email.me> <tsmmlr$1t5d$1@nnrp.usenet.blueworldhosting.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cd8b9ac4-51d1-4293-97aa-214c8a25c4e8n@googlegroups.com>
Subject: Re: Is it possible to convert strings to math operators?
From: jason.cy.kwan@gmail.com (Kpop 2GM)
Injection-Date: Wed, 08 Mar 2023 20:44:44 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Kpop 2GM - Wed, 8 Mar 2023 20:44 UTC

although these strictly aren't "math operators", you can build an eval() function specifically for relational operators with a very short syntax :

function compare(__, _, ___) {
…. return +__==+___ \
….…. ? _ ~ "[^!]=" \
….…. : (_ ~ "[!=].|.>" || +__<+___)==(_<"=")
}

0x1.0FFFFp+22. <>. 11141110000000000e-10. . 1. 4456444. 1114111
0x1.0FFFFp+22. ==. 11141110000000000e-10. . 0. 4456444. 1114111
0x1.0FFFFp+22. !=. 11141110000000000e-10. . 1. 4456444. 1114111

0x1.0FFFFp+22. >. 11141110000000000e-10. . 1. 4456444. 1114111
0x1.0FFFFp+22. >=. 11141110000000000e-10. . 1. 4456444. 1114111
0x1.0FFFFp+22. <=. 11141110000000000e-10. . 0. 4456444. 1114111
0x1.0FFFFp+22. <. 11141110000000000e-10. . 0. 4456444. 1114111

0x1.0FFFFp+21. <>. 11141110000000000e-10. . 1. 2228222. 1114111
0x1.0FFFFp+21. ==. 11141110000000000e-10. . 0. 2228222. 1114111
0x1.0FFFFp+21. !=. 11141110000000000e-10. . 1. 2228222. 1114111

0x1.0FFFFp+21. >. 11141110000000000e-10. . 1. 2228222. 1114111
0x1.0FFFFp+21. >=. 11141110000000000e-10. . 1. 2228222. 1114111
0x1.0FFFFp+21. <=. 11141110000000000e-10. . 0. 2228222. 1114111
0x1.0FFFFp+21. <. 11141110000000000e-10. . 0. 2228222. 1114111

0x1.0FFFFp+20. <>. 11141110000000000e-10. . 0. 1114111. 1114111
0x1.0FFFFp+20. ==. 11141110000000000e-10. . 1. 1114111. 1114111
0x1.0FFFFp+20. !=. 11141110000000000e-10. . 0. 1114111. 1114111

0x1.0FFFFp+20. >. 11141110000000000e-10. . 0. 1114111. 1114111
0x1.0FFFFp+20. >=. 11141110000000000e-10. . 1. 1114111. 1114111
0x1.0FFFFp+20. <=. 11141110000000000e-10. . 1. 1114111. 1114111
0x1.0FFFFp+20. <. 11141110000000000e-10. . 0. 1114111. 1114111

0x1.0FFFFp+20. <>. 1114111000000000117E-12. 1. 1114111. 1114111.0000000002
0x1.0FFFFp+20. ==. 1114111000000000117E-12. 0. 1114111. 1114111.0000000002
0x1.0FFFFp+20. !=. 1114111000000000117E-12. 1. 1114111. 1114111.0000000002

0x1.0FFFFp+20. >. 1114111000000000117E-12. 0. 1114111. 1114111.0000000002
0x1.0FFFFp+20. >=. 1114111000000000117E-12. 0. 1114111. 1114111.0000000002
0x1.0FFFFp+20. <=. 1114111000000000117E-12. 1. 1114111. 1114111.0000000002
0x1.0FFFFp+20. <. 1114111000000000117E-12. 1. 1114111. 1114111.0000000002

0x1.0FFFFp+19. <>. 11141110000000000e-10. . 1. 557055.5. 1114111
0x1.0FFFFp+19. ==. 11141110000000000e-10. . 0. 557055.5. 1114111
0x1.0FFFFp+19. !=. 11141110000000000e-10. . 1. 557055.5. 1114111

0x1.0FFFFp+19. >. 11141110000000000e-10. . 0. 557055.5. 1114111
0x1.0FFFFp+19. >=. 11141110000000000e-10. . 0. 557055.5. 1114111
0x1.0FFFFp+19. <=. 11141110000000000e-10. . 1. 557055.5. 1114111
0x1.0FFFFp+19. <. 11141110000000000e-10. . 1. 557055.5. 1114111

** the relational operator "<>" is treated as NOT_EQUAL "!=" even though it's not part of awk syntax

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor