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

Method toInt64

src/common/DecFloat.cpp:765–794  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

763}
764
765SINT64 Decimal128::toInt64(DecimalStatus decSt, int scale) const
766{
767 static CDecimal128 quant(1);
768
769 Decimal128 wrk(*this);
770 wrk.setScale(decSt, -scale);
771 wrk = wrk.quantize(decSt, quant);
772
773 if (wrk.compare(decSt, i64min) < 0 || wrk.compare(decSt, i64max) > 0)
774 {
775 DecimalContext context(this, decSt, true);
776 decContextSetStatus(&context, DEC_Invalid_operation);
777 return 0; // in case of no trap on invalid operation
778 }
779
780 unsigned char coeff[DECQUAD_Pmax];
781 int sign = decQuadGetCoefficient(&wrk.dec, coeff);
782 SINT64 rc = 0;
783
784 for (int i = 0; i < DECQUAD_Pmax; ++i)
785 {
786 rc *= 10;
787 if (sign)
788 rc -= coeff[i];
789 else
790 rc += coeff[i];
791 }
792
793 return rc;
794}
795
796UCHAR* Decimal128::getBytes()
797{

Callers

nothing calls this directly

Calls 4

decContextSetStatusFunction · 0.85
quantizeMethod · 0.80
setScaleMethod · 0.45
compareMethod · 0.45

Tested by

no test coverage detected