MantisBT - OCaml
View Issue Details
0005829OCamlstandard librarypublic2012-11-16 05:232017-02-17 16:43
berenger 
 
normalminoralways
resolvedno change required 
Intel_x86_64Linuxsqueeze/sid
4.00.0 
4.03.0 
0005829: int_of_string failure
This fails:
int_of_string " 123";;
Exception: (Failure int_of_string).

While this works:
float_of_string " 123";;
- : float = 123.

I am a little surprised.

Regards,
F.
int_of_string " 1";;
These also fail:
# int_of_string "1 ";;
Exception: Failure "int_of_string".
# float_of_string "1.0 ";;
Exception: Failure "float_of_string".
No tags attached.
related to 0006296closed  inconsistent behavior of float_of_string (compare to "ints"_of_string) 
related to 0006649closed  int_of_string fails on integers starting with a + 
Issue History
2012-11-16 05:23berengerNew Issue
2012-11-16 17:50frischNote Added: 0008518
2012-11-16 17:50frischSeveritycrash => minor
2012-12-19 02:39berengerNote Added: 0008628
2013-06-28 17:34doligezStatusnew => confirmed
2013-06-28 17:34doligezTarget Version => 4.02.0+dev
2013-07-12 18:15doligezTarget Version4.02.0+dev => 4.01.1+dev
2014-01-18 08:34hhugoNote Added: 0010810
2014-01-18 08:36gascheRelationship addedrelated to 0006296
2014-05-25 20:20doligezTarget Version4.01.1+dev => 4.02.0+dev
2014-07-30 20:59doligezTarget Version4.02.0+dev => 4.02.1+dev
2014-09-04 00:25doligezTarget Version4.02.1+dev => undecided
2014-09-24 19:46doligezTarget Versionundecided => 4.02.2+dev / +rc1
2015-03-13 22:07doligezTarget Version4.02.2+dev / +rc1 => 4.03.0+dev / +beta1
2015-07-25 09:06xleroyRelationship addedrelated to 0006649
2016-03-24 11:59doligezTarget Version4.03.0+dev / +beta1 => 4.03.1+dev
2017-02-16 14:01doligezTarget Version4.03.1+dev => undecided
2017-02-17 16:43xleroyNote Added: 0017317
2017-02-17 16:43xleroyStatusconfirmed => resolved
2017-02-17 16:43xleroyResolutionopen => no change required
2017-02-17 16:43xleroyFixed in Version => 4.03.0
2017-02-17 16:43xleroyTarget Versionundecided =>
2017-02-23 16:43doligezCategoryOCaml standard library => standard library

Notes
(0008518)
frisch   
2012-11-16 17:50   
(Downgrading severity from crash to minor: it's a matter of choice whether those functions should ignore leading/trailing whitespace.)
(0008628)
berenger   
2012-12-19 02:39   
Consistency in the choice would be nice.
(0010810)
hhugo   
2014-01-18 08:34   
http://caml.inria.fr/mantis/view.php?id=6296 [^]
(0017317)
xleroy   
2017-02-17 16:43   
float_of_string is often more tolerant than int_of_string regarding whitespace and number syntax, because the former relies on strtod() from the C standard library, which itself is not fully specified. This fact was documented in 4.03 for float_of_string:

"The format of decimal floating-point numbers is [...] Depending on the execution platforms, other representations of floating-point numbers can be accepted, but should not be relied upon."

Making float_of_string stricter just for the sake of consistency is not worth the effort.