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

Function decFloatNextMinus

extern/decNumber/decBasic.c:2692–2722  ·  view source on GitHub ↗

------------------------------------------------------------------ */ decFloatNextMinus -- next towards -Infinity */ / result gets the next lesser decFloat */ dfl is the decFloat to start with */ set is the context */ returns result

Source from the content-addressed store, hash-verified

2690/* an sNaN). */
2691/* ------------------------------------------------------------------ */
2692decFloat * decFloatNextMinus(decFloat *result, const decFloat *dfl,
2693 decContext *set) {
2694 decFloat delta; // tiny increment
2695 uInt savestat; // saves status
2696 enum rounding saveround; // .. and mode
2697
2698 // +Infinity is the special case
2699 if (DFISINF(dfl) && !DFISSIGNED(dfl)) {
2700 DFSETNMAX(result);
2701 return result; // [no status to set]
2702 }
2703 // other cases are effected by sutracting a tiny delta -- this
2704 // should be done in a wider format as the delta is unrepresentable
2705 // here (but can be done with normal add if the sign of zero is
2706 // treated carefully, because no Inexactitude is interesting);
2707 // rounding to -Infinity then pushes the result to next below
2708 decFloatZero(&delta); // set up tiny delta
2709 DFWORD(&delta, DECWORDS-1)=1; // coefficient=1
2710 DFWORD(&delta, 0)=DECFLOAT_Sign; // Sign=1 + biased exponent=0
2711 // set up for the directional round
2712 saveround=set->round; // save mode
2713 set->round=DEC_ROUND_FLOOR; // .. round towards -Infinity
2714 savestat=set->status; // save status
2715 decFloatAdd(result, dfl, &delta, set);
2716 // Add rules mess up the sign when going from +Ntiny to 0
2717 if (DFISZERO(result)) DFWORD(result, 0)^=DECFLOAT_Sign; // correct
2718 set->status&=DEC_Invalid_operation; // preserve only sNaN status
2719 set->status|=savestat; // restore pending flags
2720 set->round=saveround; // .. and mode
2721 return result;
2722 } // decFloatNextMinus
2723
2724/* ------------------------------------------------------------------ */
2725/* decFloatNextPlus -- next towards +Infinity */

Callers

nothing calls this directly

Calls 2

decFloatZeroFunction · 0.85
decFloatAddFunction · 0.85

Tested by

no test coverage detected