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

Applying std-lib function "sin" to values near pi leads to wild output when evaluating with the ocaml interpreter #6868

Closed
vicuna opened this issue May 13, 2015 · 2 comments

Comments

@vicuna
Copy link

vicuna commented May 13, 2015

Original bug ID: 6868
Reporter: rand
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2016-12-07T10:49:19Z)
Resolution: not a bug
Priority: urgent
Severity: major
OS: Ubuntu
OS Version: 14.04
Version: 4.02.0
Category: runtime system and C interface
Monitored by: rand

Bug description

The faulty output only happens when evaluating the expression directly in toplevel or as script to ocaml - the output is correct when having compiled to byte-/native-code.

I have reproduced this for other ocaml compilers on the same computer, and on a different machine running ubuntu 14.10.

Steps to reproduce

ocaml <(echo "print_float (sin 3.14159265358979312)")

1.22464679915e-16

ocaml <(echo "print_float (sin 3.1416358979312)")

-4.32443413933e-05

ocaml <(echo "print_float (sin 3.1415358979312)")

5.6755658563e-05

@vicuna
Copy link
Author

vicuna commented May 13, 2015

Comment author: @garrigue

I cannot see what is wrong.
You apply sin to a value that differs from pi by about 5e-5, and you get a value of about 5e-5.
Mathematically this seems correct:

let pi = 4. *. atan 1.;;

val pi : float = 3.14159265358979312

let f x = (pi -. x, sin x);;

val f : float -> float * float =

f 3.14159265358979312;;

  • : float * float = (0., 1.22464679914735321e-16)

f 3.1416358979312;;

  • : float * float = (-4.32443414069005883e-05, -4.32443413932997734e-05)

f 3.1415358979312;;

  • : float * float = (5.67556585933104429e-05, 5.67556585629626416e-05)

@vicuna
Copy link
Author

vicuna commented May 13, 2015

Comment author: rand

I'm sorry.. missed the 'e' syntax :/ Will check thrice in the future.

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

2 participants