|
nsz |
0c7d46 |
#include <math.h>
|
|
nsz |
0c7d46 |
#include <stdint.h>
|
|
nsz |
0c7d46 |
#include <fenv.h>
|
|
nsz |
0c7d46 |
#include <stdio.h>
|
|
nsz |
0c7d46 |
#include <float.h>
|
|
nsz |
6b77f1 |
#include <stdlib.h>
|
|
nsz |
ce441c |
#include "fenvutil.h"
|
|
nsz |
6b77f1 |
#include "test.h"
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
static struct {
|
|
nsz |
0c7d46 |
int round;
|
|
nsz |
0c7d46 |
double x;
|
|
nsz |
0c7d46 |
long n;
|
|
nsz |
0c7d46 |
int except;
|
|
nsz |
0c7d46 |
} t[] = {
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x0p+0, 0, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x0p+0, 0, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x0p+0, 0, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x0p+0, 0, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p-2, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p-2, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p-2, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p-1, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p-1, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.8p-1, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.8p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.8p-1, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.8p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.8p-1, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.8p-1, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.8p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.8p-1, 0, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p+0, 1, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p+0, 1, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p+0, 1, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p+0, 1, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p+0, -1, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p+0, -1, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p+0, -1, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p+0, -1, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.4p+0, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.4p+0, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.4p+0, 2, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.4p+0, 1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.4p+0, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.4p+0, -2, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.4p+0, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.4p+0, -1, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p+30, 1073741824, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p+30, 1073741824, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p+30, 1073741824, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p+30, 1073741824, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p+30, -1073741824, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p+30, -1073741824, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p+30, -1073741824, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p+30, -1073741824, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.fffffffcp+30, 2147483647, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.fffffffcp+30, 2147483647, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.fffffffcp+30, 2147483647, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.fffffffcp+30, 2147483647, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.fffffffcp+30, -2147483647, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.fffffffcp+30, -2147483647, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.fffffffcp+30, -2147483647, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.fffffffcp+30, -2147483647, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p+31, -2147483648, 0,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p+31, -2147483648, 0,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p+31, -2147483648, 0,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p+31, -2147483648, 0,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.00000002p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.fffffffep+30, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.fffffffep+30, 2147483647, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.fffffffep+30, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.fffffffep+30, 2147483647, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.fffffffep+30, -2147483648, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.fffffffep+30, -2147483648, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.fffffffep+30, -2147483647, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.fffffffep+30, -2147483647, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.00000001p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.00000001p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.00000001p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.00000001p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.00000001p+31, -2147483648, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.00000001p+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.00000001p+31, -2147483648, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.00000001p+31, -2147483648, FE_INEXACT,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1p+32, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, 0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, 0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, 0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, 0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TONEAREST, -0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_DOWNWARD, -0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_UPWARD, -0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
FE_TOWARDZERO, -0x1.ffffffffp+31, 0, FE_INVALID,
|
|
nsz |
0c7d46 |
};
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
void test_lrint()
|
|
nsz |
0c7d46 |
{
|
|
nsz |
a9d0a0 |
int f, i;
|
|
nsz |
0c7d46 |
long n;
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
for (i = 0; i < sizeof t/sizeof *t; i++) {
|
|
nsz |
0c7d46 |
fesetround(t[i].round);
|
|
nsz |
0c7d46 |
feclearexcept(FE_ALL_EXCEPT);
|
|
nsz |
0c7d46 |
n = lrint(t[i].x);
|
|
nsz |
0c7d46 |
f = fetestexcept(FE_ALL_EXCEPT);
|
|
nsz |
0c7d46 |
|
|
nsz |
ce441c |
if (t[i].except != FE_INVALID && n != t[i].n)
|
|
nsz |
ce441c |
error("round=%s, lrint(%a) want %ld got %ld\n", strround(t[i].round), t[i].x, t[i].n, n);
|
|
nsz |
ce441c |
if (f != t[i].except)
|
|
nsz |
ce441c |
error("round=%s, lrint(%a)==%ld want except=%s, got except=%s\n",
|
|
nsz |
ce441c |
strround(t[i].round), t[i].x, t[i].n, strdup(strexcept(t[i].except)), strdup(strexcept(f)));
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
void bench_lrint_simple(int N)
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
int i;
|
|
nsz |
0c7d46 |
volatile int n;
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
for (i = 0; i < N; i++) {
|
|
nsz |
0c7d46 |
n = lrint(1.25);
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
void bench_lrint_hard(int N)
|
|
nsz |
0c7d46 |
{
|
|
nsz |
0c7d46 |
int i;
|
|
nsz |
0c7d46 |
volatile int n;
|
|
nsz |
0c7d46 |
|
|
nsz |
0c7d46 |
for (i = 0; i < N; i++) {
|
|
nsz |
0c7d46 |
// feclearexcept(FE_ALL_EXCEPT);
|
|
nsz |
0c7d46 |
// n = lrint(1.5);
|
|
nsz |
0c7d46 |
// n = lrint(0x1p32);
|
|
nsz |
0c7d46 |
// n = lrint(-0x1p31);
|
|
nsz |
0c7d46 |
n = lrint(0x1p31+0.5);
|
|
nsz |
0c7d46 |
}
|
|
nsz |
0c7d46 |
}
|