Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

I'm all for computer dating, but I wouldn't want one to marry my sister.


devel / comp.unix.shell / Re: [ksh] 64 bit long integer type

SubjectAuthor
* [ksh] 64 bit long integer typeJanis Papanagnou
+* [ksh] 64 bit long integer typeJanis Papanagnou
|`* [ksh] 64 bit long integer typeJanis Papanagnou
| +- [ksh] 64 bit long integer typeJanis Papanagnou
| `- [ksh] 64 bit long integer typeMartijn Dekker
`- [ksh] 64 bit long integer typeCyrille Lefevre

1
[ksh] 64 bit long integer type

<udf8qq$3fpfn$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7147&group=comp.unix.shell#7147

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: [ksh] 64 bit long integer type
Date: Fri, 8 Sep 2023 15:50:17 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <udf8qq$3fpfn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 13:50:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c5c6d48dec2199353cc1c33e677b37ac";
logging-data="3663351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tyiheRYnsVZW0gKNhQ+x7"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:Frc22RSTBTf8yYrOQj4/qDsDv10=
X-Mozilla-News-Host: news://news.eternal-september.org:119
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Fri, 8 Sep 2023 13:50 UTC

Usually it is sufficient for me to work in Kornshell with integers
(typeset -i) that support 32 bit (signed) data.

Now playing with long integers (typeset -li) and 64 bit data I got
puzzled about the results... (the two lines marked with "???")

typeset -i x=$(getconf UINT_MAX) # -1 fff..ff
typeset -i x=$(getconf ULONG_MAX) # 0 doesn't fit
typeset -li x=$(getconf UINT_MAX) # 4294967295 positive in '-li'
typeset -li x=$(getconf ULONG_MAX) # -9223372036854775808 ???
typeset -li16 x=$(getconf ULONG_MAX) # 16#8000000000000000 ???
getconf ULONG_MAX # 18446744073709551615 fff..ff
typeset -li x=16#ffffffffffffffff # -1

What conversion/truncation/whatever happens when assigning a
ULONG_MAX (which is an all '1's number) to a long int [signed]
type (where only the highest bit gets set, that obviously defines
the minimum signed value)?

Note that for 'typeset -i' and UINT_MAX it is an all '1's binary
number, the decimal -1. And 'typeset -li' is capable of carrying
64 '1' bits.

(BTW; there's no overflow error indication reported or a RC>0.)

Janis

Re: [ksh] 64 bit long integer type

<udfaiu$3g001$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7149&group=comp.unix.shell#7149

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: [ksh] 64 bit long integer type
Date: Fri, 8 Sep 2023 16:20:14 +0200
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <udfaiu$3g001$1@dont-email.me>
References: <udf8qq$3fpfn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 8 Sep 2023 14:20:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="64ecf13caed83f083d203d8261ebbac3";
logging-data="3670017"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+VxvOdhOEac3xqYHOVyTb8"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:yRjscA2ARSbnXJi/z26l1R+mFng=
In-Reply-To: <udf8qq$3fpfn$1@dont-email.me>
 by: Janis Papanagnou - Fri, 8 Sep 2023 14:20 UTC

On 08.09.2023 15:50, Janis Papanagnou wrote:
> Usually it is sufficient for me to work in Kornshell with integers
> (typeset -i) that support 32 bit (signed) data.
>
> Now playing with long integers (typeset -li) and 64 bit data I got
> puzzled about the results... (the two lines marked with "???")
>
> typeset -i x=$(getconf UINT_MAX) # -1 fff..ff
> typeset -i x=$(getconf ULONG_MAX) # 0 doesn't fit
> typeset -li x=$(getconf UINT_MAX) # 4294967295 positive in '-li'
> typeset -li x=$(getconf ULONG_MAX) # -9223372036854775808 ???
> typeset -li16 x=$(getconf ULONG_MAX) # 16#8000000000000000 ???
> getconf ULONG_MAX # 18446744073709551615 fff..ff
> typeset -li x=16#ffffffffffffffff # -1

Using unsigned types may shed some light on the issue...

$ typeset -lui x=$(getconf ULONG_MAX) ; echo $x
9223372036854775808

....not that this result wouldn't open more/other questions.

>
> What conversion/truncation/whatever happens when assigning a
> ULONG_MAX (which is an all '1's number) to a long int [signed]
> type (where only the highest bit gets set, that obviously defines
> the minimum signed value)?
>
> Note that for 'typeset -i' and UINT_MAX it is an all '1's binary
> number, the decimal -1. And 'typeset -li' is capable of carrying
> 64 '1' bits.
>
> (BTW; there's no overflow error indication reported or a RC>0.)
>
> Janis
>

Re: [ksh] 64 bit long integer type

<udki61$jibq$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7156&group=comp.unix.shell#7156

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: [ksh] 64 bit long integer type
Date: Sun, 10 Sep 2023 16:00:32 +0200
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <udki61$jibq$1@dont-email.me>
References: <udf8qq$3fpfn$1@dont-email.me> <udfaiu$3g001$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 14:00:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0ab03941ceb4fc83916c18bbe62e17c0";
logging-data="641402"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dKqkzaUGstIOHjEd/dcFK"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:rA8P0rdw73nOORiM4o5YOGe5vLQ=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <udfaiu$3g001$1@dont-email.me>
 by: Janis Papanagnou - Sun, 10 Sep 2023 14:00 UTC

It seems the below observed output is the result of a _float based_
long-int math. Ksh's man page says in chapter Arithmetic Evaluation:
"Evaluations are performed using double precision floating point
arithmetic or long double precision floating point for systems
that provide this data type."
Results seem thus be system dependent and (on my system) [unsigned]
long integer calculations should not be done with values greater than
9223372036854775807 (if not less than that; I haven't yet confirmed
the reliability), and 64 bit certainly aren't supported.

typeset UINT_MAX ULONG_MAX (expected)
4294967295 18446744073709551615

-i -1 0
-ui 4294967295 0
-li 4294967295 -9223372036854775808 (-1)
-lui 4294967295 9223372036854775808 (18446744073709551615
or 9223372036854775807)

On 08.09.2023 16:20, Janis Papanagnou wrote:
> On 08.09.2023 15:50, Janis Papanagnou wrote:
>> Usually it is sufficient for me to work in Kornshell with integers
>> (typeset -i) that support 32 bit (signed) data.
>>
>> Now playing with long integers (typeset -li) and 64 bit data I got
>> puzzled about the results... (the two lines marked with "???")
>>
>> typeset -i x=$(getconf UINT_MAX) # -1 fff..ff
>> typeset -i x=$(getconf ULONG_MAX) # 0 doesn't fit
>> typeset -li x=$(getconf UINT_MAX) # 4294967295 positive in '-li'
>> typeset -li x=$(getconf ULONG_MAX) # -9223372036854775808 ???
>> typeset -li16 x=$(getconf ULONG_MAX) # 16#8000000000000000 ???
>> getconf ULONG_MAX # 18446744073709551615 fff..ff
>> typeset -li x=16#ffffffffffffffff # -1
>
> Using unsigned types may shed some light on the issue...
>
> $ typeset -lui x=$(getconf ULONG_MAX) ; echo $x
> 9223372036854775808
>
> ...not that this result wouldn't open more/other questions.
>
>>
>> What conversion/truncation/whatever happens when assigning a
>> ULONG_MAX (which is an all '1's number) to a long int [signed]
>> type (where only the highest bit gets set, that obviously defines
>> the minimum signed value)?
>>
>> Note that for 'typeset -i' and UINT_MAX it is an all '1's binary
>> number, the decimal -1. And 'typeset -li' is capable of carrying
>> 64 '1' bits.
>>
>> (BTW; there's no overflow error indication reported or a RC>0.)
>>
>> Janis
>>
>

Re: [ksh] 64 bit long integer type

<udkmun$k8ah$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7157&group=comp.unix.shell#7157

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: [ksh] 64 bit long integer type
Date: Sun, 10 Sep 2023 17:21:58 +0200
Organization: A noiseless patient Spider
Lines: 82
Message-ID: <udkmun$k8ah$1@dont-email.me>
References: <udf8qq$3fpfn$1@dont-email.me> <udfaiu$3g001$1@dont-email.me>
<udki61$jibq$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 15:21:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0ab03941ceb4fc83916c18bbe62e17c0";
logging-data="663889"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bNEEIOLl/OesqFK8eCu3y"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:NBdIS1AueHzXV6LElZaNibjxyJI=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <udki61$jibq$1@dont-email.me>
 by: Janis Papanagnou - Sun, 10 Sep 2023 15:21 UTC

It gets even more interesting...

$ typeset -li x=9223372036854775807 ; echo $((x))
9223372036854775807
$ typeset -li x=9223372036854775808 ; echo $((x))
-9223372036854775808

$ typeset -li x=10#9223372036854775807 ; echo $((x))
9223372036854775807
$ typeset -li x=10#9223372036854775808 ; echo $((x))
ksh: typeset: 10#9223372036854775808: arithmetic syntax error

$ typeset -li x=$(getconf ULONG_MAX) ; echo $((x))
-9223372036854775808
$ typeset -li x=10#$(getconf ULONG_MAX) ; echo $((x))
ksh: typeset: 10#18446744073709551615: arithmetic syntax error

....you can trigger an error message (which is good!) by explicitly
specifying the numeric base '10#' with the number.

On 10.09.2023 16:00, Janis Papanagnou wrote:
> It seems the below observed output is the result of a _float based_
> long-int math. Ksh's man page says in chapter Arithmetic Evaluation:
> "Evaluations are performed using double precision floating point
> arithmetic or long double precision floating point for systems
> that provide this data type."
> Results seem thus be system dependent and (on my system) [unsigned]
> long integer calculations should not be done with values greater than
> 9223372036854775807 (if not less than that; I haven't yet confirmed
> the reliability), and 64 bit certainly aren't supported.
>
> typeset UINT_MAX ULONG_MAX (expected)
> 4294967295 18446744073709551615
>
> -i -1 0
> -ui 4294967295 0
> -li 4294967295 -9223372036854775808 (-1)
> -lui 4294967295 9223372036854775808 (18446744073709551615
> or 9223372036854775807)
>
>
> On 08.09.2023 16:20, Janis Papanagnou wrote:
>> On 08.09.2023 15:50, Janis Papanagnou wrote:
>>> Usually it is sufficient for me to work in Kornshell with integers
>>> (typeset -i) that support 32 bit (signed) data.
>>>
>>> Now playing with long integers (typeset -li) and 64 bit data I got
>>> puzzled about the results... (the two lines marked with "???")
>>>
>>> typeset -i x=$(getconf UINT_MAX) # -1 fff..ff
>>> typeset -i x=$(getconf ULONG_MAX) # 0 doesn't fit
>>> typeset -li x=$(getconf UINT_MAX) # 4294967295 positive in '-li'
>>> typeset -li x=$(getconf ULONG_MAX) # -9223372036854775808 ???
>>> typeset -li16 x=$(getconf ULONG_MAX) # 16#8000000000000000 ???
>>> getconf ULONG_MAX # 18446744073709551615 fff..ff
>>> typeset -li x=16#ffffffffffffffff # -1
>>
>> Using unsigned types may shed some light on the issue...
>>
>> $ typeset -lui x=$(getconf ULONG_MAX) ; echo $x
>> 9223372036854775808
>>
>> ...not that this result wouldn't open more/other questions.
>>
>>>
>>> What conversion/truncation/whatever happens when assigning a
>>> ULONG_MAX (which is an all '1's number) to a long int [signed]
>>> type (where only the highest bit gets set, that obviously defines
>>> the minimum signed value)?
>>>
>>> Note that for 'typeset -i' and UINT_MAX it is an all '1's binary
>>> number, the decimal -1. And 'typeset -li' is capable of carrying
>>> 64 '1' bits.
>>>
>>> (BTW; there's no overflow error indication reported or a RC>0.)
>>>
>>> Janis
>>>
>>
>

Re: [ksh] 64 bit long integer type

<kmjmsmFsbq1U2@mid.individual.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7163&group=comp.unix.shell#7163

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: martijn@inlv.demon.nl (Martijn Dekker)
Newsgroups: comp.unix.shell
Subject: Re: [ksh] 64 bit long integer type
Date: Fri, 15 Sep 2023 19:42:29 +0100
Lines: 18
Message-ID: <kmjmsmFsbq1U2@mid.individual.net>
References: <udf8qq$3fpfn$1@dont-email.me> <udfaiu$3g001$1@dont-email.me>
<udki61$jibq$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 3JElVmJdtyIysm4b2h291gNnUxGbDJs6IwwHnRcOowTP10CNc=
Cancel-Lock: sha1:UUSWy1YUTbnj3kTbftCm/nA7mMM= sha256:VYteFgTlQUFxBEklUsjwZem6vp8ryyPy0IsbJIeNbNI=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0)
Gecko/20100101 Thunderbird/102.15.0
Content-Language: en-GB
In-Reply-To: <udki61$jibq$1@dont-email.me>
 by: Martijn Dekker - Fri, 15 Sep 2023 18:42 UTC

Op 10-09-2023 om 15:00 schreef Janis Papanagnou:
> It seems the below observed output is the result of a_float based_
> long-int math. Ksh's man page says in chapter Arithmetic Evaluation:
> "Evaluations are performed using double precision floating point
> arithmetic or long double precision floating point for systems
> that provide this data type."

I can certainly see the flaws of that design, but I'm afraid it's pretty much
set in stone. I'm reluctant to mess with the arithmetic evaluation subsystem,
which (like many things in the AT&T ksh code base) is very hard to understand.

--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh

Re: [ksh] 64 bit long integer type

<653afd9c$0$6080$426a74cc@news.free.fr>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7537&group=comp.unix.shell#7537

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!nntp.comgw.net!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!cleanfeed1-a.proxad.net!nnrp1-1.free.fr!not-for-mail
Date: Fri, 27 Oct 2023 02:00:29 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [ksh] 64 bit long integer type
Content-Language: fr
Newsgroups: comp.unix.shell
References: <udf8qq$3fpfn$1@dont-email.me>
From: Cyrille.Lefevre-news%nospam@laposte.net.invalid (Cyrille Lefevre)
Organization: ACME
In-Reply-To: <udf8qq$3fpfn$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 39
Message-ID: <653afd9c$0$6080$426a74cc@news.free.fr>
NNTP-Posting-Date: 27 Oct 2023 02:00:29 CEST
NNTP-Posting-Host: 78.242.206.141
X-Trace: 1698364829 news-2.free.fr 6080 78.242.206.141:37653
X-Complaints-To: abuse@proxad.net
 by: Cyrille Lefevre - Fri, 27 Oct 2023 00:00 UTC

On 08/09/2023 at 15:50, Janis Papanagnou wrote :
> Usually it is sufficient for me to work in Kornshell with integers
> (typeset -i) that support 32 bit (signed) data.
>
> Now playing with long integers (typeset -li) and 64 bit data I got
> puzzled about the results... (the two lines marked with "???")
>
> typeset -i x=$(getconf UINT_MAX) # -1 fff..ff
> typeset -i x=$(getconf ULONG_MAX) # 0 doesn't fit
> typeset -li x=$(getconf UINT_MAX) # 4294967295 positive in '-li'
> typeset -li x=$(getconf ULONG_MAX) # -9223372036854775808 ???
> typeset -li16 x=$(getconf ULONG_MAX) # 16#8000000000000000 ???
> getconf ULONG_MAX # 18446744073709551615 fff..ff
> typeset -li x=16#ffffffffffffffff # -1
>
> What conversion/truncation/whatever happens when assigning a
> ULONG_MAX (which is an all '1's number) to a long int [signed]
> type (where only the highest bit gets set, that obviously defines
> the minimum signed value)?
>
> Note that for 'typeset -i' and UINT_MAX it is an all '1's binary
> number, the decimal -1. And 'typeset -li' is capable of carrying
> 64 '1' bits.
>
> (BTW; there's no overflow error indication reported or a RC>0.)
>
> Janis

Hi,

consider filling a bug report here https://github.com/ksh93/ksh/issues

Regards,

Cyrille Lefevre.
--
mailto:Cyrille.Lefevre-news%nospam@laposte.net.invalid
remove "%nospam" and ".invalid" to answer me.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor