HP aC++/HP ANSI C A.06.28 Release (769149-001, March 2014)
exit(EXIT_FAILURE);
}
if (s == EOF) break;
}
else if (encoding == bid) {
r = (int) fread(&be, sizeof(_Binaryencoding64), 1, inp);
if (r != 1) break;
m = _decodebinary64(be); // decode bid
}
else /* encoding == dpd */ {
r = (int) fread(&de, sizeof(_Decimalencoding64), 1, inp);
if (r != 1) break;
m = _decodedecimal64(de); // decode dpd
}
// compute hours billed
fe_dec_setround(FE_DEC_UPWARD);
h = m / 60;
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.
36 Product changes in earlier versions