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

Re: inconsistent long number truncation



Stephane Chazelas wrote on Tue, Oct 09, 2018 at 07:50:14 +0100:
> I think the:
> 
> 
>           newcalc = calc * base + *s - '0';
>           if (newcalc < calc)
> 
> Is an invalid way to check for numbers wrapping.
> 

Obviously right, as your examples show:

> (gdb) p calc
> $7 = 12345678901234567890
> (gdb) p calc*10
> $8 = 12776324570088369204

> Why do we truncate in the first place?

Judging by the comment at the top of the function, might that be for
compatibility with some strtol() implementation [that once was] out there?



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