>>4
also known as "Round-to-even" for obvious reasons
Name:
Anonymous2007-05-17 14:22 ID:SbNGR/9+
I think Prelude was crafted by someone who wanted to write bank software. They would then use these rounding errors to misdirect funds. Jewish in its tenacity, as it were.
Name:
Anonymous2007-05-17 15:38 ID:3nyFrU8H
It looks like it's fracked up to me. Either your rounding should be a ceiling or floor function, but not both as it seems with round 2.5 and round 3.5 to have both features. This can be fixed in the return statement, btw.
Name:
Anonymous2007-05-17 16:04 ID:hyPVJoYB
>>7
if you want ceiling or floor, type ceiling(ceil?) or floor!
round generally implies some funny stuff at .5
Name:
Anonymous2007-05-17 17:53 ID:lPw2XWds
>>8
That funny stuff is either go up or go down, not go to whatever fuck number I feel like going this time.
>>11
Disregard that, I suck cocks. I just read about round-to-even for the first time.
But still, if they're using that they should at least document it. The reference manual just describes the round function as "round x returns the nearest integer to x".
Name:
Anonymous2007-05-18 1:58 ID:hE6c/gZf
>>12
At n + 0.5 (with integer n) both n and n + 1 are the exact same distance. It does exactly what it says.
round to even is for gayfags. real men round toward the nearest power of e**pi.
Name:
Anonymous2007-05-18 3:41 ID:4RaxYkdm
>>12 But still, if they're using that they should at least document it.
Round-to-even is the proper way of doing it in all of science, economics, accounting, engineering... They teach this shit in grade school. How does one not know this?
Name:
Anonymous2007-05-18 5:30 ID:YQm8yWVM
>>15
Went through CS, hadn't heard of it. What's its awesome property justifying its insanity? You should just go up. Who the fuck cares if it's even or not? And why would moneyfags care for that?
Name:
Anonymous2007-05-18 5:31 ID:YQm8yWVM
Also, banks and employers should use businessround, which consists of rounding downwards if it's your money, or upwards if it's theirs.
Name:
Anonymous2007-05-18 5:43 ID:4RaxYkdm
>>16
>What's its awesome property justifying its insanity?
Statistics.
If I round up a thousand values with one decimal place to the nearest integer and sum them, 1/10th of those times will be a five, so you're 100 over the real value. If you round to even, half those go up and half go down, so you get the true value with many nines precision.
This may not seem like a lot, but think about it. Every month, your interest is compounded on your bank account. They round to the nearest penny. Say they have a million accounts, each one gets interest compounded and rounded, 1/10th of the time ends in a five, so if they round up they're overpaying $10,000 a month. That's a big chunk of change to not add up in the books.
Why should you always go up? 0.5 is an equal distance away from both 0 and 1. Doing round-to-even smooths out the slight bias you can get from always rounding up.
use Quantum::Superpositions;
sub round($){
my($n)=@_;
return int($n)+($n-int$n>.5)-($n-int$n<-.5)+any(0,(any(-1,1)==2*($n-int$n)));
}
Name:
Anonymous2007-05-18 12:03 ID:YQm8yWVM
>>18
+1 Insightful
I understand, though consider floating point numbers don't stop at the first fractionary digit; actually the 5 that you'll arbitrarily round up (or down) will be far smaller for this to matter much. You can rely on having 16-17 decimal digits at the very least, and we can consider 1 million accounts will have an average of 5 digit accounts. This will mean there'll be at least 10 fractional digits, and you lose or win (if a bank or employer, win) just 1E-10 * 1E-1 * 1E+6 = 1E-5 dollars. Not even Scrooge would care for that.
>>15
Dude, I was taught in the local equivalent of grade school that 0.5 rounds _up_ by convention.
Then again, 0.5 (and 1.5, 2.5 etc) are those numbers that you cannot have exactly using a floating-point representation. So in financial code it's better to use an epsilon-sensitive comparison thing and call floor or ceil by hand. ... actually, in financial code it's best not to use floating point types at all.
Name:
Anonymous2007-05-20 2:06 ID:UsKkJi5O
>>30
No, 0.5, 1.5, 2.5, etc., are *exactly* the kind of number you can represent with binary floating point numbers because they're sums of integral powers of two, fucktard.
I think you'd be surprised how much financial code is implemented using floating point, especially in software for small and medium businesses. It's fine unless you're handling huge amounts that can't be accurately stored by the precision available.
But yes, ideally you should implement currency calculations as integer calculations in the smallest denomination (e.g. cents, pennies etc)
Name:
Anonymous2007-05-20 14:55 ID:3ZWK+hAH
internally represented as a number * a scale
eg 5*10^-1
But in a computer its binary
?*2^?
Name:
Anonymous2007-05-20 14:56 ID:3ZWK+hAH
>>33
so 1.5 is actually 1.49999
and 2.5 is actualy 2.5000012
>>38
Yes, most languages use a special "money" type internally when working with money-related numbers. This usually results in better performance, although compilation takes slightly longer.
Name:
Anonymous2007-05-21 15:30 ID:PmYYMD3K
SPOILER: Currency types are just integers. Except 100 actually represents 1.00 or whatever.
Only shitty languages have them as primitives.
Name:
Anonymous2007-05-21 15:32 ID:5yYaqzBB
>Only enterprise languages have them as primitives.
fixed
Name:
Anonymous2007-05-21 15:34 ID:1bh/6waX
FUCKING JEWS STEAL MAH MONIES
KILL ALL JEWS
Name:
Anonymous2007-05-21 16:23 ID:GTz7eOXR
>>39
My god, that must be from the Cobol era. Nowadays, you use long integers. If you're handling lawyers money, you use long longs (64 bit integers). Compilation is pretty fast. Sometimes you don't even compile code because it's interpreted.
>>42
Lawyers are the ones stealing your money every day. Just by existing, because they sit their asses in the congress and other places and waste your tax money complicating law and inventing all sorts of stupid shit such as liability for extraterrestrial attacks or imaginary property rights. Lawyers are the pest of this society, kill a lawyer, save a life.