Maths Function Precision
This page documents the accuracy characteristics of the math functions in SCALE's device runtime
library.
The tables below express the error in terms of ULP. Roughly, this means "how many floating point numbers away from the
most-correct representable value can it be?"
Bold values indicate that the function was tested for all inputs (every possible bit pattern).
Other values were calculated by testing billions of arguments per function, chosen to
include the values maths functions often get wrong and the ranges where results are hardest to
get right (which varies somewhat based on the properties of each function).
For the exhaustively tested functions with any error, each section's "Distribution of errors" shows
the proportion of arguments with each error, among those whose result is finite. Hover over a
percentage to see the exact count.
Where a function's result is infinite or zero, its sign matches NVIDIA's implementation.
Where it is a NaN, its sign and payload are unspecified: you'll get a NaN, but not
necessarily the same one NVIDIA produce. This is because there would be a meaningful
performance cost to matching that, and the correct way to compare NaNs (isnan())
doesn't care.
The accuracy bounds cover all supported GPU architectures.
Functions not listed here have an accuracy of 0ULP for all inputs. Empty
cells in the table indicate that the CUDA API does not provide that function
for that data type.
NVIDIA documents its own bounds in the
CUDA Programming Guide.
Exponentials and logarithms
| Function |
float |
double |
__half |
__nv_bfloat16 |
exp |
1 |
1 |
0 |
0 |
exp2 |
1 |
1 |
0 |
0 |
exp10 |
1 |
1 |
0 |
0 |
expm1 |
1 |
1 |
|
|
log |
1 |
1 |
0 |
0 |
log2 |
1 |
1 |
0 |
0 |
log10 |
2 |
1 |
0 |
0 |
log1p |
1 |
1 |
|
|
Distribution of float errors
| Function |
0 ULP |
1 ULP |
2 ULP |
Mean |
exp |
99.7% |
0.339% |
|
0.00339 |
exp2 |
99.0% |
0.979% |
|
0.00979 |
exp10 |
98.1% |
1.89% |
|
0.0189 |
expm1 |
99.7% |
0.341% |
|
0.00341 |
log |
99.4% |
0.578% |
|
0.00578 |
log2 |
50.7% |
49.3% |
|
0.493 |
log10 |
51.6% |
47.3% |
1.08% |
0.495 |
log1p |
99.9% |
0.129% |
|
0.00129 |
Powers and roots
| Function |
float |
double |
__half |
__nv_bfloat16 |
Notes |
pow |
2 |
2 |
|
|
|
sqrt |
0 |
0 |
0 |
0 |
|
rsqrt |
1 |
1 |
0 |
0 |
|
rcp |
|
|
0 |
0 |
|
cbrt |
1 |
1 |
|
|
|
rcbrt |
1 |
1 |
|
|
|
hypot |
1 |
1 |
|
|
|
rhypot |
2 |
1 |
|
|
|
norm3d |
1 |
1 |
|
|
|
rnorm3d |
2 |
1 |
|
|
|
norm4d |
1 |
1 |
|
|
|
rnorm4d |
2 |
1 |
|
|
|
norm |
1 |
1 |
|
|
Tested on 4 elements. |
rnorm |
2 |
1 |
|
|
Tested on 4 elements. |
Distribution of float errors
| Function |
0 ULP |
1 ULP |
Mean |
rsqrt |
89.0% |
11.0% |
0.11 |
cbrt |
99.9% |
0.0515% |
0.000515 |
rcbrt |
99.96% |
0.0392% |
0.000392 |
Trigonometric functions
| Function |
float |
double |
__half |
__nv_bfloat16 |
sin |
1 |
1 |
0 |
0 |
cos |
1 |
1 |
0 |
0 |
sincos |
1 |
1 |
|
|
tan |
2 |
2 |
|
|
sinpi |
1 |
1 |
|
|
cospi |
1 |
1 |
|
|
sincospi |
1 |
1 |
|
|
asin |
2 |
1 |
|
|
acos |
1 |
1 |
|
|
atan |
2 |
2 |
|
|
atan2 |
1 |
2 |
|
|
Distribution of float errors
| Function |
0 ULP |
1 ULP |
2 ULP |
Mean |
sin |
92.1% |
7.89% |
|
0.0789 |
cos |
92.0% |
7.99% |
|
0.0799 |
tan |
84.4% |
15.6% |
0.0128% |
0.157 |
sinpi |
83.3% |
16.7% |
|
0.167 |
cospi |
99.2% |
0.762% |
|
0.00762 |
asin |
99.5% |
0.490% |
0.0267% |
0.00544 |
acos |
92.4% |
7.62% |
|
0.0762 |
atan |
95.5% |
4.49% |
0.00581% |
0.0451 |
Hyperbolic functions
| Function |
float |
double |
__half |
__nv_bfloat16 |
sinh |
2 |
1 |
|
|
cosh |
1 |
1 |
|
|
tanh |
1 |
1 |
0 |
0 |
tanh_approx |
|
|
0 |
0 |
asinh |
2 |
2 |
|
|
acosh |
2 |
2 |
|
|
atanh |
2 |
2 |
|
|
Distribution of float errors
| Function |
0 ULP |
1 ULP |
2 ULP |
Mean |
sinh |
96.7% |
3.27% |
0.00201% |
0.0327 |
cosh |
97.7% |
2.25% |
|
0.0225 |
tanh |
99.9% |
0.126% |
|
0.00126 |
asinh |
84.9% |
15.1% |
0.0000317% |
0.151 |
acosh |
72.3% |
27.7% |
0.000159% |
0.277 |
atanh |
97.6% |
2.42% |
0.0000719% |
0.0242 |
Error and gamma functions
| Function |
float |
double |
Notes |
erf |
1 |
1 |
|
erfc |
3 |
4 |
|
erfinv |
2 |
4 |
|
erfcinv |
3 |
4 |
|
erfcx |
3 |
4 |
|
normcdf |
3 |
4 |
|
normcdfinv |
4 |
4 |
|
tgamma |
3 |
3 |
double: Exact on the integers 1 to 23. |
lgamma |
5 |
4 |
double: For x outside [-23.0001, -2.2637]. Otherwise unbounded. |
Distribution of float errors
| Function |
0 ULP |
1 ULP |
2 ULP |
3 ULP |
4 ULP |
5 ULP |
Mean |
erf |
99.3% |
0.692% |
|
|
|
|
0.00692 |
erfc |
96.0% |
3.90% |
0.0589% |
0.00000393% |
|
|
0.0402 |
erfinv |
88.0% |
12.0% |
0.000389% |
|
|
|
0.12 |
erfcinv |
48.6% |
45.7% |
5.70% |
0.0850% |
|
|
0.573 |
erfcx |
75.1% |
24.0% |
0.882% |
0.00000368% |
|
|
0.258 |
tgamma |
93.2% |
6.73% |
0.0720% |
0.000201% |
|
|
0.0687 |
lgamma |
84.5% |
14.9% |
0.597% |
0.0158% |
0.0000296% |
0.000000480% |
0.161 |
Bessel functions
| Function |
float |
double |
Notes |
j0 |
3 |
3 |
float: For |x| < 8. Otherwise, absolute error 2.2e-6.
double: For |x| < 8. Otherwise, absolute error 5e-12. |
j1 |
2 |
3 |
As j0. |
y0 |
3 |
3 |
As j0. |
y1 |
2 |
3 |
As j0. |
jn |
see notes |
see notes |
float: Absolute error 2.2e-6 for n = 128.
double: Absolute error 5e-12 for n = 128. |
yn |
see notes |
see notes |
float: ceil(2 + 2.5n) ulps for |x| < n, and absolute error 2.2e-6 otherwise.
double: Absolute error 5e-12 for |x| > 1.5n. |
cyl_bessel_i0 |
4 |
3 |
|
cyl_bessel_i1 |
4 |
4 |
|