Skip to content

Instantly share code, notes, and snippets.

@wilzbach
Last active August 9, 2016 02:10
Show Gist options
  • Save wilzbach/3d27d06b55821aa9795deb15d4d47679 to your computer and use it in GitHub Desktop.
Save wilzbach/3d27d06b55821aa9795deb15d4d47679 to your computer and use it in GitHub Desktop.
FP precision with sin
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));
}
}
> 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