Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created April 30, 2017 15:43
Show Gist options
  • Save Vaguery/93163c1736d2b1aff3cefdd6c4a98b9b to your computer and use it in GitHub Desktop.
Save Vaguery/93163c1736d2b1aff3cefdd6c4a98b9b to your computer and use it in GitHub Desktop.
Reproducing the Java/ARMv8 `Math/log` bug
# intended to be run on an ARMv8 machine at packet.net
apt-get update
apt-get install default-jre
apt-get install wget
wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
chmod +x lein
mv lein /usr/local/bin
lein repl
# hit ENTER to get past root login warning
# ... lein downloads scads of stuff
# type the following into lein repl prompts, a line at a time:
(def arg (* 2 Math/E)) ;; defines a constant
(Math/log arg) ;; returns the ln(2e)
;; on Intel machines running Oracle JDK 8, that result is 1.6931471805599452
(assert (= (Math/log arg) 1.6931471805599452)) ;; fails, because on ARMv8 it doesn't equal that
@Vaguery
Copy link
Author

Vaguery commented Apr 30, 2017

Two comments:

  1. it may be that the open-JDK version vs the Oracle JDK 8 version differ; I have not checked
  2. the error only crops up for some tested arguments; I see no problems in any other tests, and I have a dozen or so

@vielmetti
Copy link

OK, thanks for the writeup.

The test matrix seems to be

  • Oracle JDK 8 vs OpenJDK 7,8,9 (4 possibilities)
  • Intel vs ARMv8 (2 possibilities)

that's "only" 8, and it occurs to me that this might be entirely the sort of thing that Docker is good for. Make 8 Dockerfiles, build each of them, compare the results.

I've seen similar exceptional behavior in Go on just the exp() call so there might be some funky transcendental computations. Or it might just be rounding rules that are underspecified, I don't know yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment