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

[IEEE 754] OCaml does not enable rounding direction to be specified by programs #7896

Open
vicuna opened this Issue Jan 16, 2019 · 4 comments

Comments

Projects
None yet
4 participants
@vicuna
Copy link
Collaborator

vicuna commented Jan 16, 2019

Original bug ID: 7896
Reporter: sfuric
Status: new
Resolution: open
Priority: normal
Severity: minor
Version: 4.07.0
Category: language features
Has duplicate: #3526
Monitored by: @gasche

Bug description

Some floating-point computations require rounding direction to be specified (typically to obtain safe bounds). However OCaml does not support directly this feature, so external functions have to be written (see attached code).

Steps to reproduce

Compile files in archive with:
ocamlc -c roundingMode_stubs.c
ocamlc -c roundingMode.mli
ocamlc -c roundingMode.ml
ocamlc -custom roundingMode.cmo roundingMode_stubs.o testRounding.ml

Run:
./a.out

File attachments

@vicuna

This comment has been minimized.

Copy link
Collaborator Author

vicuna commented Jan 16, 2019

Comment author: @nojb

I'm not an expert on IEEE754, but it sounds like a potentially useful addition. Would you like to open a PR on https://github.com/ocaml/ocaml to discuss your code?

@xavierleroy

This comment has been minimized.

Copy link
Contributor

xavierleroy commented Mar 16, 2019

FP rounding mode is another piece of global state, and I don't feel like exposing this to casual users. I'd rather leave that to a specialized, external library. Even better would be a more functional API that hides the global state. Again such an API could be developed first as an external library.

@Chris00

This comment has been minimized.

Copy link
Member

Chris00 commented Mar 16, 2019

In case this is of interest, the Interval library does this (internally).

@xavierleroy

This comment has been minimized.

Copy link
Contributor

xavierleroy commented Mar 16, 2019

Yes, interval arithmetic is a great example of a nice, high-level, declarative API that changes rounding mode internally in the implementation.

Actually I wonder whether there are any other common use of non-default rounding modes beyond interval arithmetic.

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.