libm: Sync with FreeBSD (gains 6 long double functions)
[dragonfly.git] / lib / libm / src / s_roundl.c
index 07bba13..c22b64c 100644 (file)
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: head/lib/msun/src/s_roundl.c 153017 2005-12-02 13:45:06Z bde $
+ * $FreeBSD: head/lib/msun/src/s_roundl.c 257770 2013-11-06 23:44:52Z kargl $
  */
 
-#include <math.h>
+
+#include <float.h>
+#ifdef __i386__
+#include <ieeefp.h>
+#endif
+
+#include "fpmath.h"
+#include "math.h"
+#include "math_private.h"
 
 long double
 roundl(long double x)
 {
        long double t;
+       uint16_t hx;
+
+       GET_LDBL_EXPSIGN(hx, x);
+       if ((hx & 0x7fff) == 0x7fff)
+               return (x + x);
 
-       if (!isfinite(x))
-               return (x);
+       ENTERI();
 
-       if (x >= 0.0) {
+       if (!(hx & 0x8000)) {
                t = floorl(x);
-               if (t - x <= -0.5)
-                       t += 1.0;
-               return (t);
+               if (t - x <= -0.5L)
+                       t += 1;
+               RETURNI(t);
        } else {
                t = floorl(-x);
-               if (t + x <= -0.5)
-                       t += 1.0;
-               return (-t);
+               if (t + x <= -0.5L)
+                       t += 1;
+               RETURNI(-t);
        }
 }