www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/07/20/08:01:19

From: fjh AT cs DOT mu DOT OZ DOT AU (Fergus Henderson)
Subject: Re: FW: Missing strtoull()...: long long standard
20 Jul 1998 08:01:19 -0700 :
Message-ID: <19980720145511.04675.cygnus.gnu-win32@murlibobo.cs.mu.OZ.AU>
References: <35AF1517 DOT A5C180B6 AT dgs DOT monash DOT edu DOT au>
Mime-Version: 1.0
To: root <root AT jacob DOT remcomp DOT fr>
Cc: Brendan Simon <brendan AT dgs DOT monash DOT edu DOT au>, gnu-win32 AT cygnus DOT com

On 19-Jul-1998, root <root AT jacob DOT remcomp DOT fr> wrote:
> As to strtoll, my system uses atoll, what should be equivalent...
> It is not that complicated actually...
> 
> Here it is:
> ----------------------------------------------------- strtoll.c-----------
> long long _strtoll(char *str)
> {
>         long long result = 0;
>         int negative=0;
> 
>         while (*str == ' ' || *str == '\t')
>                 str++;
>         if (*str == '+')
>                 str++;
>         else if (*str == '-') {
>                 negative = 1;
>                 str++;
>         }
> 
>         while (*str >= '0' && *str <= '9') {
>                 result = (result*10)+(*str++ - '0');
>         }
>         return negative ? -result : result;
> }

That version is buggy; it won't handle the most negative number correctly.

I think changing the last few lines to
	
                 result = (result*10) - (*str++ - '0');
         }
         return negative ? result : -result;

should fix the bug.

-- 
Fergus Henderson <fjh AT cs DOT mu DOT oz DOT au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh AT 128 DOT 250 DOT 37 DOT 3        |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019