Last active
August 9, 2016 02:10
-
-
Save wilzbach/3d27d06b55821aa9795deb15d4d47679 to your computer and use it in GitHub Desktop.
FP precision with sin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
import std.stdio; | |
import std.meta : AliasSeq; | |
import std.math : PI, sin; | |
import core.stdc.math : sin_c = sin; | |
foreach (S; AliasSeq!(float, double, real)) | |
{ | |
S pi = PI; | |
writefln("x: %12s, x_c: %12s, x_c_pi: %12s", sin(S(PI)), sin_c(S(PI)), sin_c(pi)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> rdmd main.d | |
x: -8.74228e-08, x_c: 1.22465e-16, x_c_pi: -8.74228e-08 | |
x: 1.22461e-16, x_c: 1.22465e-16, x_c_pi: 1.22465e-16 | |
x: -5.42101e-20, x_c: 1.22465e-16, x_c_pi: 1.22465e-16 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment