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

format for scanf vs string_of_float #8199

Closed
vicuna opened this issue Jul 8, 2003 · 2 comments
Closed

format for scanf vs string_of_float #8199

vicuna opened this issue Jul 8, 2003 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 8, 2003

Original bug ID: 1745
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Wheeler Ruml
Version: 3.06
OS: linux
Submission from: katsura.parc.xerox.com (13.2.18.21)

Scanf doesn't seem to like the floating-point format used by
string_of_float. string_of_float is happy to print nothing after the
decimal point, but as the following code demonstrates, scanf will
raise an exception if the string ends directly after the decimal
point:

let scanf_test () =
Printf.printf "got %f.\n" (Scanf.sscanf " 24. " " %f" (fun x -> x));
(* now no space after the point *)
Scanf.sscanf " 24." " %f" (fun x -> x)

scanf_test ();;

got 24.000000.
Exception: Scanf.Scan_failure "scanf: bad input at char number 4: bad int".

I suppose one could argue that string_of_float is matched with
float_of_string and scanf is supposed to be matched with printf, and
the two pairs shouldn't necessarily be combined, but it seems like an
unnecessary incompatibility.

Thanks for some great software!

Wheeler

@vicuna
Copy link
Author

vicuna commented Jul 13, 2003

Comment author: administrator

Full_Name: Wheeler Ruml
Version: 3.06
OS: linux
Submission from: katsura.parc.xerox.com (13.2.18.21)

Scanf doesn't seem to like the floating-point format used by
string_of_float. string_of_float is happy to print nothing after the
decimal point, but as the following code demonstrates, scanf will
raise an exception if the string ends directly after the decimal
point:

let scanf_test () =
Printf.printf "got %f.\n" (Scanf.sscanf " 24. " " %f" (fun x -> x));
(* now no space after the point *)
Scanf.sscanf " 24." " %f" (fun x -> x)

scanf_test ();;

got 24.000000.
Exception: Scanf.Scan_failure "scanf: bad input at char number 4: bad int".

Thanks for the bug report: this behaviour was due to a wrong treatment
of the end of input condition and has been corrected some time ago
into the working sources.

I suppose one could argue that string_of_float is matched with
float_of_string and scanf is supposed to be matched with printf, and
the two pairs shouldn't necessarily be combined, but it seems like an
unnecessary incompatibility.

I don't clearly grasp what you mean, here. What is the incompatibility
you want to get rid of ?

Thanks for some great software!

Thank you again.

Best regards,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/

@vicuna
Copy link
Author

vicuna commented Jul 16, 2003

Comment author: administrator

Fixed by PW in 3.06+...

@vicuna vicuna closed this as completed Jul 16, 2003
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant