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

Function adjustForScale

src/common/cvt.cpp:1124–1152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1122
1123template <typename V>
1124void adjustForScale(V& val, SSHORT scale, const V limit, ErrorFunction err)
1125{
1126 if (scale > 0)
1127 {
1128 int fraction = 0;
1129 do {
1130 if (scale == 1)
1131 fraction = int(val % 10);
1132 val /= 10;
1133 } while (--scale);
1134
1135 if (fraction > 4)
1136 val++;
1137 // The following 2 lines are correct for platforms where
1138 // ((-85 / 10 == -8) && (-85 % 10 == -5)). If we port to
1139 // a platform where ((-85 / 10 == -9) && (-85 % 10 == 5)),
1140 // we'll have to change this depending on the platform.
1141 else if (fraction < -4)
1142 val--;
1143 }
1144 else if (scale < 0)
1145 {
1146 do {
1147 if ((val > limit) || (val < -limit))
1148 err(Arg::Gds(isc_arith_except) << Arg::Gds(isc_numeric_out_of_range));
1149 val *= 10;
1150 } while (++scale);
1151 }
1152}
1153
1154
1155class SSHORTTraits

Callers 3

cvt_get_shortFunction · 0.85
CVT_get_longFunction · 0.85
CVT_get_int64Function · 0.85

Calls 1

GdsClass · 0.85

Tested by

no test coverage detected