HP aC++/HP ANSI C Release Notes (B3901-90037; A.06.26; September 2011)
h = quantized64(h, onert); // round to tenths
// compute billing amount
fe_dec_setround(FE_DEC_TONEARESTFROMZERO);
b = rate * h;
b = quantized64(b, twort); // round to hundredths
// restore decimal rounding mode to default
fe_dec_setround(FE_DEC_TONEAREST);
// print billing amount to file
fprintf(outp, "%Da\n", b);
// update sums
sumM += m;
sumH += h;
sumB += b;
} // main loop
// close files
fclose(inp);
fclose(outp);
// confirm expected quantum in sums
assert(samequantumd64(sumH, onert));
assert(samequantumd64(sumB, twort));
// print summary
printf("SUMMARY:\n");
printf(" number of calls = %d\n", n);
printf(" total minutes = %Da\n", sumM);
printf(" total hours billed = %Da\n", sumH);
printf(" total amount billed = %Da\n", sumB);
return 0;
}
Notes:
• The quantize functions do the work of rounding to the desired number of places to
the right of the decimal point. They return the value of their first argument represented
with the quantum exponent of their second argument, rounding if necessary.
• Mixing decimal FP and integer operands, as in the expression m / 60, is allowed.
However, the expression m / 60.0, which mixes decimal and binary FP, would
cause an error.
• On the HP-UX implementation, BID data could be read directly into the decimal FP
variable m, without the need of decoding. However, that code would not be portable
to systems that use DPD encoding for their decimal FP types.
• Restoring the default rounding has no effect in this program, except perhaps if the
ASCII input had more than 16 decimal digits, but doing so is a good programming
practice.
28 Product changes in earlier versions