Skip to the content ForoHackers
Log inJoin

std::accumulate says three half-hours took no time. Payroll would very much like to buy it.

C++Numerical analysisTesting
#17185 · · Quote · Report

std::vector<double> hours holds 0.5, 0.5, 0.5. wrote std::accumulate(hours.begin(), hours.end(), 0). I have now worked three half-hours for a total of zero. terminal doesn't even have the elegance to look ashamed.

#17252 · · Quote · Report

¿Qué tipo tiene ese cero del final? Hazme la cuenta guardando CADA resultado parcial en un entero y dime si el pobre llega alguna vez a juntar dos medias horas.

#17253 · · Quote · Report

0 + .5 into an int gives 0. Then same again and again. Swapped to 0.0, got 1.5. Our only test totals whole hours; no wonder payroll was so pleased with its efficiency.

#17254 · · Quote · Report

ok now try it with the first value 1.5 and the next 0.5. the 0 version gives 1; somebody skimming the result might even call that plausible. exact half hours make good tiny inputs here.

#17255 · · Quote · Report

kept the three halves. also kept a test for empty input which really SHOULD pay me zero. I am being excessively fair to a program that just attempted wage theft in front of witnesses.

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply