Last change
on this file since 559 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.3 KB
|
Rev | Line | |
---|
[444] | 1 | /* lroundf adapted to be llroundf for Newlib, 2009 by Craig Howland. */ |
---|
| 2 | /* |
---|
| 3 | * ==================================================== |
---|
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
---|
| 5 | * |
---|
| 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
---|
| 7 | * Permission to use, copy, modify, and distribute this |
---|
| 8 | * software is freely granted, provided that this notice |
---|
| 9 | * is preserved. |
---|
| 10 | * ==================================================== |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #include "fdlibm.h" |
---|
| 14 | |
---|
| 15 | long long int |
---|
| 16 | llroundf(float x) |
---|
| 17 | { |
---|
| 18 | __int32_t exponent_less_127; |
---|
| 19 | __uint32_t w; |
---|
| 20 | long long int result; |
---|
| 21 | __int32_t sign; |
---|
| 22 | |
---|
| 23 | GET_FLOAT_WORD (w, x); |
---|
| 24 | exponent_less_127 = ((w & 0x7f800000) >> 23) - 127; |
---|
| 25 | sign = (w & 0x80000000) != 0 ? -1 : 1; |
---|
| 26 | w &= 0x7fffff; |
---|
| 27 | w |= 0x800000; |
---|
| 28 | |
---|
| 29 | if (exponent_less_127 < (int)((8 * sizeof (long long int)) - 1)) |
---|
| 30 | { |
---|
| 31 | if (exponent_less_127 < 0) |
---|
| 32 | return exponent_less_127 < -1 ? 0 : sign; |
---|
| 33 | else if (exponent_less_127 >= 23) |
---|
| 34 | result = (long long int) w << (exponent_less_127 - 23); |
---|
| 35 | else |
---|
| 36 | { |
---|
| 37 | w += 0x400000 >> exponent_less_127; |
---|
| 38 | result = w >> (23 - exponent_less_127); |
---|
| 39 | } |
---|
| 40 | } |
---|
| 41 | else |
---|
| 42 | return (long long int) x; |
---|
| 43 | |
---|
| 44 | return sign * result; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | #ifdef _DOUBLE_IS_32BITS |
---|
| 48 | |
---|
| 49 | long long int |
---|
| 50 | llround(double x) |
---|
| 51 | { |
---|
| 52 | return llroundf((float) x); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | #endif /* defined(_DOUBLE_IS_32BITS) */ |
---|
Note: See
TracBrowser
for help on using the repository browser.