To reproduce:
-
Use an ARM64 computer (tested on M1 mac and on Raspberry Pi model 4B)
- On Raspberry pi, I used Raspbian:bookworm
- On M1 mac, I used
docker run --rm -ti -v $(pwd):/demo -w /demo debian:bookworm /bin/bash
(which shares the local directory into the container, assumes you are running this from the cloned gist)
-
On your computer of choice, run
apt update && apt install -y build-essential clang-13 clang
-
Observe gcc produces correct results:
gcc ./min-repro-sample.c && ./a.out
The number printed here is expected to be 0.0. GCC (all versions tested) produces the correct result. Clang 14.0.6 introduces small numerical error, producing a value > 0 The latest version of clang tested producing the correct result is clang 13.0.1 (from debian:bookwork clang-13) result: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000 On clang 14.0.6, the calculated result below is a workaround that produces the expected 0.0 result: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000
-
Observe clang-13 produces correct results:
clang-13 ./min-repro-sample.c && ./a.out
The number printed here is expected to be 0.0. GCC (all versions tested) produces the correct result. Clang 14.0.6 introduces small numerical error, producing a value > 0 The latest version of clang tested producing the correct result is clang 13.0.1 (from debian:bookwork clang-13) result: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000 On clang 14.0.6, the calculated result below is a workaround that produces the expected 0.0 result: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000
-
Observe clang-14 produces unexpected results:
clang-14 ./min-repro-sample.c && ./a.out
The number printed here is expected to be 0.0. GCC (all versions tested) produces the correct result. Clang 14.0.6 introduces small numerical error, producing a value > 0 The latest version of clang tested producing the correct result is clang 13.0.1 (from debian:bookwork clang-13) result: 0.00000000000000004058614543027810527553055411362964847252091191848188955759724195 On clang 14.0.6, the calculated result below is a workaround that produces the expected 0.0 result: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000