'number types (function returns "wrong" result)
I'm running Function Accuracy Test tool (in Julia 1.7.2 on 64-bit Ubuntu 18.04) and test sin() function. Problem is the result sin(x...) and sin(big, x)...) which function calls gives.
Here's an example of few input values (Float16):
( Range: -0.7853982f0:1.570798f-6:0.7853982f0 )
x -0.7853982
Comparison: sin(x...) -0.70710677 vs sin(map(big, x)...) -0.7071067966408574982218873068639201062404313604169267415232690981467895117867091
x -0.78539664
Comparison: sin(x...) -0.7071057 vs sin(map(big, x)...) -0.7071057008219710592610583916121386335507498121453599174530436043153324651900249
x -0.785395
Comparison: sin(x...) -0.70710456 vs sin(map(big, x)...) -0.7071045628544069335831518159655666916535017380441150694175707960861677701383995
x -0.7853935
Comparison: sin(x...) -0.7071035 vs sin(map(big, x)...) -0.7071034670320587628440324684003875993008018017656187324934698375469763027284935
Debug data for the first x value:
Wolfram|Alpha (and Octave) gives different results:
sin(-0.7853982) = -0.707106807068459559730712471249650919086696271494555843865775956...
sin(-0.78539664)= -0.707105703981060877385398550052561039837195399228112767226085558...
sin(-0.785395) = -0.707104544323222201909737214474462553610953144479787635566743062...
sin(-0.7853935) = -0.707103483658899645499967038364728301664644014034519844381265599...
Octave results are equal with Wolfram|Alpha.
Which results are correct?
How (with what number type) can I get equal results from Julia?
Solution 1:[1]
This is just you taking the sin of different numbers. -0.7853982f0!=-0.7853982!=big"-0.7853982". The key is that most numbers with decimals aren't exactly representable as binary floating point numbers. -0.7853982f0 is the closest Float32 to the decimal number. -0.7853982 is the closest Float64 value, and big"-0.7853982" is the closest BigFloat. The way FunctionAccuracyTests works is it tests the function against the bigfloat version of x, not the bigfloat version of the decimal number that x was close to. This is what you want for testing accuracy of functions, but is a little confusing here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oscar Smith |

