Navigation Menu

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

Improved display of abnormal floats #8233

Closed
vicuna opened this issue Jul 25, 2003 · 4 comments
Closed

Improved display of abnormal floats #8233

vicuna opened this issue Jul 25, 2003 · 4 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Jul 25, 2003

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

Bug description

Float of string accepts the strings "nan", "inf" and "-inf".

Ocaml(top) always display those value with a dot at the end. eg.,

:; ocaml
Objective Caml version 3.07+beta 1

nan;;

  • : float = nan.

infinity;;

  • : float = inf.

neg_infinity;;

  • : float = -inf.

Could you get rid of the excess dot?

While we're on the topic, this behavior is good:

float_of_string "nan";;

  • : float = nan.

float_of_string "inf";;

  • : float = inf.

float_of_string "-inf";;

  • : float = -inf.

Why does entering those values only work for nan?

nan;;

  • : float = nan.

inf;;

Unbound value inf

Oh, the ocamltop lexer treats "nan" as an identifier and there happens
to be a Pervasives.nan which is a handy coincidence. I almost was
going to mention that if the tokens "infinity" and "neg_infinity" were
used instead of "inf" and "-inf" this might be considered a good
thing. Most likely this is not a good thing.

@vicuna
Copy link
Author

vicuna commented Jul 26, 2003

Comment author: administrator

Hi Damien,

Damien Doligez wrote (2003-07-26T20:51:04+0200):

Float of string accepts the strings "nan", "inf" and "-inf".

Not on my machine. I guess it depends on the C standard library.

Yes. I took a look at the source. I thought there was a special case
for those tokens. It depends on the C standard library.

Ocaml(top) always display those value with a dot at the end. eg.,
[...]
Could you get rid of the excess dot?

This is now done in the working source.

Thanks. The dot has obvious lexical problems. I like to be able to
take the output from an ocaml session and use it as input. This is
handy for regression tests and other such stuff. I was happy when
3.05 displayed all floats like a lexical float.

Oh, the ocamltop lexer treats "nan" as an identifier and there happens
to be a Pervasives.nan which is a handy coincidence. I almost was
going to mention that if the tokens "infinity" and "neg_infinity" were
used instead of "inf" and "-inf" this might be considered a good
thing. Most likely this is not a good thing.

I'm not sure I understand what you mean here. It would be easy
to define "inf" in pervasives, but for "-inf" we would need to hack
the lexer or the parser. I'm not sure we want to do that.

Maybe the values that string_of_float ought to return a "nan",
"infinity" and "neg_infinity"? I suspect that once again this is
under the control of the standard C library.

-cheers

@vicuna
Copy link
Author

vicuna commented Jul 26, 2003

Comment author: administrator

Hi John,

Float of string accepts the strings "nan", "inf" and "-inf".

Not on my machine. I guess it depends on the C standard library.

Ocaml(top) always display those value with a dot at the end. eg.,
[...]
Could you get rid of the excess dot?

This is now done in the working source.

Oh, the ocamltop lexer treats "nan" as an identifier and there happens
to be a Pervasives.nan which is a handy coincidence. I almost was
going to mention that if the tokens "infinity" and "neg_infinity" were
used instead of "inf" and "-inf" this might be considered a good
thing. Most likely this is not a good thing.

I'm not sure I understand what you mean here. It would be easy
to define "inf" in pervasives, but for "-inf" we would need to hack
the lexer or the parser. I'm not sure we want to do that.

-- Damien

@vicuna
Copy link
Author

vicuna commented Jul 29, 2003

Comment author: administrator

While we're on the topic, this behavior is good:

float_of_string "nan";;

  • : float = nan.

float_of_string "inf";;

  • : float = inf.

float_of_string "-inf";;

  • : float = -inf.

Why does entering those values only work for nan?

nan;;

  • : float = nan.

inf;;

Unbound value inf

By coincidence. The strings "nan", "inf", "-inf" depend on the C
library implementation of printf for floats. Hopefully, the same C
library can read them back using strtod, which corresponds to
float_of_string in Caml. But other C libraries may chose different names.

So, we can't guarantee that these names will match those of the float
constants nan, infinity, neg_infinity defined in Pervasives. Moreover,
"-inf" would cause a slight parsing/typing problem...

However, in the spirit of "the Caml toplevel should be able to read
back what it prints", I'll change the toplevel printing of floats so
that the strings "nan", "infinity" and "neg_infinity" are used for the
corresponding float values.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Jul 29, 2003

Comment author: administrator

Display of nan and inf: fixed by DD 2003-07-26
Top-level display of nan and inf changed to allow top-level readback by XL
2003-07-29.

@vicuna vicuna closed this as completed Jul 29, 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