MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / decToIntegral

Function decToIntegral

extern/decNumber/decBasic.c:3874–3908  ·  view source on GitHub ↗

------------------------------------------------------------------ */ decToIntegral -- local routine to effect ToIntegral value */ / result gets the result */ df is the decFloat to round */ set is the context */ rmode is the rounding mode to use

Source from the content-addressed store, hash-verified

3872/* returns result */
3873/* ------------------------------------------------------------------ */
3874static decFloat * decToIntegral(decFloat *result, const decFloat *df,
3875 decContext *set, enum rounding rmode,
3876 Flag exact) {
3877 Int exp; // exponent
3878 uInt sourhi; // top word from source decFloat
3879 enum rounding saveround; // saver
3880 uInt savestatus; // ..
3881 decFloat zero; // work
3882
3883 /* Start decoding the argument */
3884 sourhi=DFWORD(df, 0); // top word
3885 exp=DECCOMBEXP[sourhi>>26]; // get exponent high bits (in place)
3886
3887 if (EXPISSPECIAL(exp)) { // is special?
3888 // NaNs are handled as usual
3889 if (DFISNAN(df)) return decNaNs(result, df, NULL, set);
3890 // must be infinite; return canonical infinity with sign of df
3891 return decInfinity(result, df);
3892 }
3893
3894 /* Here when the argument is finite */
3895 // complete extraction of the exponent
3896 exp+=GETECON(df)-DECBIAS; // .. + continuation and unbias
3897
3898 if (exp>=0) return decCanonical(result, df); // already integral
3899
3900 saveround=set->round; // save rounding mode ..
3901 savestatus=set->status; // .. and status
3902 set->round=rmode; // set mode
3903 decFloatZero(&zero); // make 0E+0
3904 decFloatQuantize(result, df, &zero, set); // 'integrate'; cannot fail
3905 set->round=saveround; // restore rounding mode ..
3906 if (!exact) set->status=savestatus; // .. and status, unless exact
3907 return result;
3908 } // decToIntegral

Callers 2

decFloatToIntegralValueFunction · 0.85
decFloatToIntegralExactFunction · 0.85

Calls 5

decInfinityFunction · 0.85
decCanonicalFunction · 0.85
decFloatZeroFunction · 0.85
decFloatQuantizeFunction · 0.85
decNaNsFunction · 0.70

Tested by

no test coverage detected