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

Comments

Projects
None yet
1 participant
@vicuna
Copy link
Collaborator

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

This comment has been minimized.

Copy link
Collaborator 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

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Dec 19, 2012

Comment author: berenger

Consistency in the choice would be nice.

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 18, 2014

Comment author: @hhugo

#6296

@vicuna

This comment has been minimized.

Copy link
Collaborator 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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.