Commit 3f58c1b9 authored by Damien George's avatar Damien George

leon: Add implementation of nearbyint.

parent a115bde3
#include <stdint.h>
#include <math.h>
static const double toint = 4503599627370496.0; // 2**52
double nearbyint(double x) {
union { double f; uint64_t i; } u = {x};
int e = u.i >> 52 & 0x7ff;
int s = u.i >> 63;
if (e >= 0x3ff + 52) {
// Large enough that it doesn't have a fraction
} else if (s) {
x -= toint;
x += toint;
if (x == 0) {
x = -0.0;
}
} else {
x += toint;
x -= toint;
}
return x;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment