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

infinity literal #7186

Closed
vicuna opened this issue Mar 18, 2016 · 8 comments
Closed

infinity literal #7186

vicuna opened this issue Mar 18, 2016 · 8 comments
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Mar 18, 2016

Original bug ID: 7186
Reporter: pierpa
Status: closed (set by @mshinwell on 2016-12-08T11:55:09Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: Windows
OS: any
OS Version: any
Version: 4.01.0
Target version: 4.03.1+dev
Category: ~DO NOT USE (was: OCaml general)
Related to: #4688
Monitored by: braibant @dra27

Bug description

I expected the following to work, but it doesn't:

float_of_string (string_of_float infinity);;

Exception: Failure "float_of_string".

I need an infinity literal which is accepted by float_of_string.

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: @dbuenzli

I suspect you are hitting the problem of locale dependent floating point conversion (See PR #6701). Which platform are you using ?

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: pierpa

As far as I understand, it's not the same issue.

(string_of_float infinity) evaluates to "inf", which I don't think is dependent from locale.

The same behaviour has been observed on windows and on linux

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: @dbuenzli

Then I don't know, but I can't reproduce what you mention on either osx or Ubuntu 14.04 LTS 64 bits.

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: pierpa

Actually, the confirmation on Linux was due to a misunderstanding.

Currently, AFAIK, it's only present on windows.

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: @dbuenzli

Search the bt for infinity there have been issues with this in the past.

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: @gasche

Indeed, in #4688 David Allsopp contributed a patch to fix string_of_float on Windows (see the patch "v2" in the issue's Attached Files). If you proposed a patch using the same conditional logic to override the float_of_string behavior on "inf", "-inf" and "nan" in the Windows case, I think it would be a good idea.

@vicuna
Copy link
Author

vicuna commented Mar 18, 2016

Comment author: pierpa

I think that would be too much work just for exploring Ocaml a bit.
The following is a good enough workaround for my current needs.
Thank you!

let less_buggy_float_of_string s =
match s with
| "inf" -> infinity
| "-inf" -> neg_infinity
| "nan" -> nan
| _ -> float_of_string s;;

@vicuna
Copy link
Author

vicuna commented Dec 8, 2016

Comment author: @mshinwell

It seems there is nothing to do here.

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