March 02, 2007
Dear community,

I am a rather new user of the D Language. Forgive me if I repeat something that is already known. Being an engineer, I am more interested in mathematical stuff. I discovered the following problems with the standard conversion functions atof and atoi:

1. The standard atof or atoi functions convert any garbage like "abc" to zero.
2. If the input string represents a valid number, but too big;
- atof returns inf. This is not too bad but you find out this either when you convert it back to a string, which returns "inf" or when you explicitly test with the isinf function. That may be too late...
- atoi returns an integer value, which is something wrong.

I believe in both cases they should throw an exception.

My Environment in short:
DMD Compiler version 1.007
MS Vista 32 Bit
AMD Athlon 64 X2 4200

Best regards,

Kagan
March 03, 2007
Kagan Kayal wrote:
> 1. The standard atof or atoi functions convert any garbage like "abc" to zero.
> 2. If the input string represents a valid number, but too big;
> - atof returns inf. This is not too bad but you find out this either when you convert it back to a string, which returns "inf" or when you explicitly test with the isinf function. That may be too late...
> - atoi returns an integer value, which is something wrong.
> 
> I believe in both cases they should throw an exception.

atof and atoi are from the C library, and behave according to the C standard.  std.conv has functions that throw exceptions on errors.