emscripten-core / emscripten-core/emscripten

Error: sinf and cosf return wrong values in iOS Safari 12 / iOS Chrome 12

Open
#13,130 4 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

I created a test project to show this behavior: https://carlosrafaelgn.com.br/sincos/source.zip

The test can also be accessed here: https://carlosrafaelgn.com.br/sincos/

Using emcc --version
emcc (Emscripten gcc/clang-like replacement) 2.0.11 (6e28e4fa4fa1bc50d58b9ddbbb9603a3cf21ea9e)

I have also tried adding -s MIN_SAFARI_VERSION=110000, but the results were the same.

In summary, sin and cos work OK, but sinf and cosf return wrong results for values >= PI.

I have not tested the entire range, but *I would guess*, based on the source https://github.com/emscripten-core/emscripten/blob/master/system/lib/libc/musl/src/math/sinf.c , that the results mess up for values >= PI / 4.

Browsers/devices tested with error:

Safari - Actual device - iPad Air updated to 12.4.9
Mozilla/5.0 (iPad; CPU OS 12_4_9 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version 12.1.2 Mobile/15E148 Safari/604.1

Safari - Browserstack - iPad Air 2019 12
Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1 Mobile/15E148 Safari/604.1

Chrome - Browserstack - iPad Air 2019 12
Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/86.0.4240.93 Mobile/15E148 Safari/604.1

Result:

Double
i Angle (deg) sin cos
0 0 0 1
1 0.5729577951308232 0.009999833334166664 0.9999500004166653
2 1.1459155902616465 0.01999866669333308 0.9998000066665778
3 1.7188733853924696 0.02999550020249566 0.9995500337489875
4 2.291831180523293 0.03998933418663416 0.9992001066609779
5 178.85408440973836 0.01999866669333322 -0.9998000066665778
6 179.4270422048692 0.009999833334166574 -0.9999500004166653
7 180 1.2246467991473532e-16 -1
8 180.5729577951308 -0.00999983333416633 -0.9999500004166653
9 181.14591559026167 -0.019998666693332976 -0.9998000066665778
10 357.7081688194767 -0.03998933418663444 0.9992001066609779
11 358.2811266146075 -0.029995500202496153 0.9995500337489875
12 358.8540844097384 -0.019998666693332896 0.9998000066665778
13 359.4270422048692 -0.009999833334166696 0.9999500004166653
14 360 -2.4492935982947064e-16 1

Float
i Angle (deg) sinf cosf
0 0 0 1
1 0.5729577823242186 0.009999833069741726 0.9999499917030334
2 1.1459155646484371 0.019998665899038315 0.9998000264167786
3 1.7188733469726556 0.029995499178767204 0.9995500445365906
4 2.2918311292968743 0.03998933359980583 0.9992001056671143
5 178.85409051152496 -0.025460606440901756 0.9807993173599243
6 179.42704776024064 -0.01566101238131523 0.9803205132484436
7 180.00000500895632 -0.0058669582940638065 0.9797232151031494
8 180.57296225767203 0.003920361399650574 0.9790068864822388
9 181.1459195063877 0.013699752278625965 0.978171169757843
10 357.7081810230499 10.551661491394043 18.876144409179688
11 358.28112461138727 10.743476867675781 19.152164459228516
12 358.8540955204813 10.938101768493652 19.43185043334961
13 359.42703910881863 11.135555267333984 19.715219497680664
14 360.00001001791264 11.335891723632812 20.00234031677246

Expected result, tested on:

Safari - Browserstack - iPad Air 2019 13
Safari - Browserstack - iPad Air 2019 14
Chrome (Latest) - Windows
Firefox (Latest) - Windows
Chrome (Latest) - Android
Edge (Latest) - Android

Double
i Angle (deg) sin cos
0 0 0 1
1 0.5729577951308232 0.009999833334166664 0.9999500004166653
2 1.1459155902616465 0.01999866669333308 0.9998000066665778
3 1.7188733853924696 0.02999550020249566 0.9995500337489875
4 2.291831180523293 0.03998933418663416 0.9992001066609779
5 178.85408440973836 0.01999866669333322 -0.9998000066665778
6 179.4270422048692 0.009999833334166574 -0.9999500004166653
7 180 1.2246467991473532e-16 -1
8 180.5729577951308 -0.00999983333416633 -0.9999500004166653
9 181.14591559026167 -0.019998666693332976 -0.9998000066665778
10 357.7081688194767 -0.03998933418663444 0.9992001066609779
11 358.2811266146075 -0.029995500202496153 0.9995500337489875
12 358.8540844097384 -0.019998666693332896 0.9998000066665778
13 359.4270422048692 -0.009999833334166696 0.9999500004166653
14 360 -2.4492935982947064e-16 1

Float
i Angle (deg) sinf cosf
0 0 0 1
1 0.5729577823242186 0.009999833069741726 0.9999499917030334
2 1.1459155646484371 0.019998665899038315 0.9998000264167786
3 1.7188733469726556 0.029995499178767204 0.9995500445365906
4 2.2918311292968743 0.03998933359980583 0.9992001056671143
5 178.85409051152496 0.01999855972826481 -0.9998000264167786
6 179.42704776024064 0.009999736212193966 -0.9999499917030334
7 180.00000500895632 -8.742277657347586e-8 -1
8 180.57296225767203 -0.009999911300837994 -0.9999499917030334
9 181.1459195063877 -0.019998734816908836 -0.9998000264167786
10 357.7081810230499 -0.03998912125825882 0.9992001056671143
11 358.28112461138727 -0.02999553456902504 0.9995500445365906
12 358.8540955204813 -0.019998472183942795 0.9998000264167786
13 359.42703910881863 -0.009999887086451054 0.9999499917030334
14 360.00001001791264 1.7484555314695172e-7 1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.