Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Determining the length of "long"?



On Fri, Sep 12, 2014 at 04:16:27PM -0700, Bart Schaefer wrote:
> On Sep 12,  9:42am, Dominik Vogt wrote:
> }
> } On Thu, Sep 11, 2014 at 09:39:01PM -0700, Bart Schaefer wrote:
> } > if (( ${#:-"$(( [#2] (1<<31)))"} > ${#:-"$(( [#2] (1<<63)))"} ))
> } > then print "zsh integer type is 32 bits"
> } > elif (( ${#:-"$(( [#2] (1<<63)))"} > ${#:-"$(( [#2] (1<<64)))"} ))
> } > then print "zsh integer type is 64 bits"
> } > else print "zsh integer type is more than 64 bits"
> } > fi
> } 
> } Hm, I'm not really sure that works reliably because the shift
> } amount may be truncated before it is used.  I.e. on s390 "1 << 32"
> } and "1 << 64" and "1 << 0" are all the same.
> 
> That probably means that zsh uses a 32 bit integer type on s390.
> There is a reason the shift in my "if" above is 1<<31 not 32.

To clarify, on s390 (1 << 31) has the same result as (1 << 63) *if*
the integer type is long (which I doubt, zsh probably uses long
long).  So this is not correct

> } > if (( ${#:-"$(( [#2] (1<<31)))"} > ${#:-"$(( [#2] (1<<63)))"} ))
                                                           ^^^^
                                                             |
                                                     this should be 32

The underlying assumption of the test that shifting an integer
value to the left by its width in bits or more yields zero is
wrong on some platforms.

Anyway, if zsh uses long long when that's available on a 32 bit
platform, the test doesn't tell me anything about long.

Ciao

Dominik ^_^  ^_^

-- 

Dominik Vogt



Messages sorted by: Reverse Date, Date, Thread, Author