On Tue, Nov 28, 2000 at 09:26:27AM +0000, Nick Ing-Simmons wrote: > Nicholas Clark <nick@ccl4.org> writes: > > > >I can't think any situation where (int)atof() would give you an answer > >better than atol() for a number matching /[-+]?[0-9]+/ > > It does if number does not fit in an integer. Aargh. atol's behaviour is undefined if number is out of range. Which means that the man page isn't quite helpful for writing portable programs if it says behaviour is as strtol. strtol and strtoll are defined as the man page says: The strtol() function returns the result of the conversion, unless the value would underflow or overflow. If an underflow occurs, strtol() re- turns LONG_MIN. If an overflow occurs, strtol() returns LONG_MAX. In both cases, errno is set to ERANGE. Can we rely on that? That's the casting behaviour we want, isn't it? I'm concerned that a string of something like (LONG_LONG_MAX-2) would get parsed and rounded by atof() to a value > (NV) LONG_LONG_MAX [can I trust floating point "==" ?] and will slip through as an NV when it should be possible to convert it to an IV. Nicholas ClarkThread Previous | Thread Next