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

Add support for hexadecimal floating-point literals #6909

Closed
vicuna opened this issue Jun 19, 2015 · 7 comments
Closed

Add support for hexadecimal floating-point literals #6909

vicuna opened this issue Jun 19, 2015 · 7 comments

Comments

@vicuna
Copy link

vicuna commented Jun 19, 2015

Original bug ID: 6909
Reporter: maro
Status: closed (set by @xavierleroy on 2017-02-16T14:16:30Z)
Resolution: fixed
Priority: low
Severity: feature
Fixed in version: 4.03.0+dev / +beta1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @dbuenzli

Bug description

It would be nice to support C99-style hexadecimal floating-point constants (such as 0x1.fp3).

Pervasives.float_of_string is already able to parse them, but supporting them as direct literals could be useful in some situations.

Are there known issues with this representation and OCaml's syntax? Or is there already ongoing work on it?

@vicuna
Copy link
Author

vicuna commented Jun 19, 2015

Comment author: @alainfrisch

Beware that float_of_string supports this notation only if the underlying libc does, which is not currently the case e.g. with MSVC ports.

@vicuna
Copy link
Author

vicuna commented Jun 22, 2015

Comment author: @xavierleroy

Yes, the hex FP notation is useful and it would be nice to support it better. As Alain Frisch wrote, we need it to be supported by the C standard library functions used by OCaml's runtime, which is the case for ISO C99-compliant libraries, but not for Microsoft's C runtime library that is used by their Visual C compiler.

@vicuna
Copy link
Author

vicuna commented Jun 22, 2015

Comment author: @alainfrisch

Is anybody aware of good (and with usable licenses) standalone implementations of functions to parse and print floating point numbers?

@vicuna
Copy link
Author

vicuna commented Jun 22, 2015

Comment author: @dbuenzli

@Frisch I think that many people would like the idea of OCaml not relying on libc for this (e.g. #6701 or the various people that are trying to have the runtime system run on bare metal).

There is this project:

https://github.com/google/double-conversion

which implements the algorithms of this paper:

http://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf

and is used by the V8 JavaScript engine. But sadly while BSD-licensed it seems to be written in C++.

@vicuna
Copy link
Author

vicuna commented Jul 24, 2015

Comment author: @xavierleroy

FYI, the C standard library of Microsoft Visual Studio 2015 seems to support "%a" (hex floats) formats in printf and scanf. However, it seems that strtod() still does not support hex floats.

@vicuna
Copy link
Author

vicuna commented Oct 27, 2015

Comment author: @xavierleroy

See proposal at #268

@vicuna
Copy link
Author

vicuna commented Nov 28, 2015

Comment author: @xavierleroy

Proposal merged, will be in 4.03.

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