Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /* IEEE754 floating point arithmetic
0003  * double precision: common utilities
0004  */
0005 /*
0006  * MIPS floating point support
0007  * Copyright (C) 1994-2000 Algorithmics Ltd.
0008  */
0009 
0010 #include "ieee754dp.h"
0011 
0012 union ieee754dp ieee754dp_fint(int x)
0013 {
0014     u64 xm;
0015     int xe;
0016     int xs;
0017 
0018     ieee754_clearcx();
0019 
0020     if (x == 0)
0021         return ieee754dp_zero(0);
0022     if (x == 1 || x == -1)
0023         return ieee754dp_one(x < 0);
0024     if (x == 10 || x == -10)
0025         return ieee754dp_ten(x < 0);
0026 
0027     xs = (x < 0);
0028     if (xs) {
0029         if (x == (1 << 31))
0030             xm = ((unsigned) 1 << 31);  /* max neg can't be safely negated */
0031         else
0032             xm = -x;
0033     } else {
0034         xm = x;
0035     }
0036 
0037     /* normalize - result can never be inexact or overflow */
0038     xe = DP_FBITS;
0039     while ((xm >> DP_FBITS) == 0) {
0040         xm <<= 1;
0041         xe--;
0042     }
0043     return builddp(xs, xe + DP_EBIAS, xm & ~DP_HIDDEN_BIT);
0044 }