atof

fixed atof(str s)

Description

Returns s parsed as a fixed-point number. If s cannot be parsed as a fixed-point number, returns 0.

If s is too big or too small to fit into a fixed-point number, returns INT_MAX with the sign of the input.

Supports Number prefixes.

This function parses the fractional part only up to the amount of digits that can be stored in a fixed-point number. This means that numbers with very long fractional parts will not be fully parsed, e.g. "0.12345678901234567890thisisnotanumberanymore!@#$^#$^$*%^*$" will parse successfully.

Examples

atoi("123") -> 123
atoi("0") -> 0
atoi("999999999999") -> 2147483647 // Too big
atoi("-99999999999") -> -2147483647 // Too small
atoi("not a number") -> 0 // Error
atoi("1.3") -> 0 // Error
atoi("0xff") -> 255 // Hexadecimal prefix