Nп/п : 41 из 100
 От   : Janis Papanagnou                    2:5075/128        08 сен 23 16:20:14
 К    : Janis Papanagnou                                      08 сен 23 17:21:03
 Тема : Re: [ksh] 64 bit long integer type
----------------------------------------------------------------------------------
                                                                                 
@MSGID: 1@dont-email.me> c82d41a0
@REPLY: 1@dont-email.me> 7571114b
@REPLYADDR Janis Papanagnou
<janis_papanagnou+ng@hotmail.com>
@REPLYTO 2:5075/128 Janis Papanagnou
@CHRS: CP866 2
@RFC: 1 0
@RFC-Message-ID: 1@dont-email.me>
@RFC-References: 1@dont-email.me>
@TZUTC: 0200
@PID: Mozilla/5.0 (X11; Linux x86_64; rv:45.0)
Gecko/20100101 Thunderbird/45.8.0
@TID: FIDOGATE-5.12-ge4e8b94
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


--- Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
 * Origin: A noiseless patient Spider (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх