Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int_of_string failure #5829

Closed
vicuna opened this issue Nov 16, 2012 · 4 comments
Closed

int_of_string failure #5829

vicuna opened this issue Nov 16, 2012 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Nov 16, 2012

Original bug ID: 5829
Reporter: berenger
Status: resolved (set by @xavierleroy on 2017-02-17T15:43:50Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: Intel_x86_64
OS: Linux
OS Version: squeeze/sid
Version: 4.00.0
Fixed in version: 4.03.0
Category: standard library
Related to: #6296 #6649

Bug description

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.

Steps to reproduce

int_of_string " 1";;

Additional information

These also fail:

int_of_string "1 ";;

Exception: Failure "int_of_string".

float_of_string "1.0 ";;

Exception: Failure "float_of_string".

@vicuna
Copy link
Author

vicuna commented Nov 16, 2012

Comment author: @alainfrisch

(Downgrading severity from crash to minor: it's a matter of choice whether those functions should ignore leading/trailing whitespace.)

@vicuna
Copy link
Author

vicuna commented Dec 19, 2012

Comment author: berenger

Consistency in the choice would be nice.

@vicuna
Copy link
Author

vicuna commented Jan 18, 2014

Comment author: @hhugo

#6296

@vicuna
Copy link
Author

vicuna commented Feb 17, 2017

Comment author: @xavierleroy

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant