blob: 934fbccab82c993b51b9ee0d81b19826f73f56ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include "libm.h"
double sqrt(double x)
{
union ldshape ux;
unsigned fpsr;
__asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x));
if ((ux.i.m & 0x7ff) != 0x400)
return (double)ux.f;
/* Rounding to double would have encountered an exact halfway case.
Adjust mantissa downwards if fsqrt rounded up, else upwards.
(result of fsqrt could not have been exact) */
ux.i.m ^= (fpsr & 0x200) + 0x300;
return (double)ux.f;
}
|