Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

round

Name: Anonymous 2007-05-17 11:03 ID:ewt37wAw

Prelude> round 0.5
0
Prelude> round 1.5
2
Prelude> round 2.5
2
Prelude> round 3.5
4


WHAT THE FUCK

Name: Anonymous 2007-05-17 11:36 ID:3jVGyPTY

Oh shit!

Name: Anonymous 2007-05-17 11:40 ID:L2S0r7qa

Round 1
Fight!

Name: Anonymous 2007-05-17 11:44 ID:Lcum8PgL

Banker's rounding

Name: Anonymous 2007-05-17 12:06 ID:Heaven

>>4
also known as "Round-to-even" for obvious reasons

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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.

Name: Anonymous 2007-05-17 18:46 ID:7V655zDh

>>7
>>9
ROUND TO EVEN, DUMBASSES.

Name: Anonymous 2007-05-17 19:01 ID:Vi/TGbmq

>>9
Actually, it should always go up at .5.

According to Hoogle, Haskell's round is defined in terms of properFraction, so I checked it out:

Prelude> map properFraction [0.5..9.5]
[(0,0.5),(1,0.5),(2,0.5),(3,0.5),(4,0.5),(5,0.5),(6,0.5),(7,0.5),(8,0.5),(9,0.5)]


Looks like everything is fine here, so I overloaded round with:

round x = if (snd $ properFraction x) >= 0.5 then ceiling x else floor x

And the results...

Prelude> map round [0.5..9.5]
[1,2,3,4,5,6,7,8,9,10]


...Now this one seems to work just fine.

WHAT THE FUCK

Name: Anonymous 2007-05-17 19:16 ID:Heaven

>>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: Anonymous 2007-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.

Name: Anonymous 2007-05-18 3:06 ID:Heaven

round to even is for gayfags. real men round toward the nearest power of e**pi.

Name: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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: Anonymous 2007-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.

Name: Anonymous 2007-05-18 5:43 ID:4RaxYkdm

>>18
Sorry, $1000 a month. Still a lot.

Name: Anonymous 2007-05-18 5:44 ID:7/OMT4ZH

>>16
round to even removes the upward bias.

Name: Anonymous 2007-05-18 6:12 ID:o4XjPboz

>>16

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.

Name: Anonymous 2007-05-18 6:13 ID:o4XjPboz

>>17

Haha

Name: Anonymous 2007-05-18 6:40 ID:ZM+GPE+N

is this thread about floating point representations of decimal numbers?

Name: Anonymous 2007-05-18 7:00 ID:9yrFW65j

ONE WORD, THE FORCED ROUNDING OF 0.5, THREAD OVER

Name: Anonymous 2007-05-18 8:47 ID:Heaven

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: Anonymous 2007-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.

Name: anonymous !faggot0tBQ 2007-05-18 12:18 ID:Heaven

>>26
gb2/slashdot, faggot.

Name: Anonymous 2007-05-18 13:06 ID:Heaven

>>13
I didn't say the definition is incorrect, faggot. I was just pointing out that it isn't clear enough.

Name: Anonymous 2007-05-18 13:16 ID:Heaven

>>27
gb2ytmnd tripfag

Name: Anonymous 2007-05-20 1:39 ID:cz/n9Z0X

>>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: Anonymous 2007-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.

Name: Anonymous 2007-05-20 14:39 ID:FThWZ74W

>>30

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: Anonymous 2007-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: Anonymous 2007-05-20 14:56 ID:3ZWK+hAH

>>33
so 1.5 is actually 1.49999
and 2.5 is actualy 2.5000012

Name: Anonymous 2007-05-20 15:05 ID:Heaven

>>34
1.5 = 1*2^0 + 1*2^-1
2.5 = 1*2^1 + 1*2^-1
3.5 = 1*2^1 + 1*2^0 + 1*2^-1

Name: Anonymous 2007-05-20 15:13 ID:FThWZ74W

>>34

That's incorrect. Look at this, and note how 1, 1/2, 1/4, 1/8 and 1/16 are stored precisely (i.e. the double is mostly 00s) and the others aren't:

$ cat > fptest.c
#include <stdio.h>

void print_bytes_of_double(double d) {

  int i;

  printf("%f is", d);
  for(i=0;i<sizeof(d);i++)
  {
    printf(" %02x", ((unsigned char*)&d)[i]);
  }
  printf("\n");
}

int main() {

  int n;
  for(n=1;n<20;n++)
  {
    print_bytes_of_double(1.0/n);
  }

}

$ cc fptest.c -o fptest
$ ./fptest
1.000000 is 00 00 00 00 00 00 f0 3f
0.500000 is 00 00 00 00 00 00 e0 3f
0.333333 is 55 55 55 55 55 55 d5 3f
0.250000 is 00 00 00 00 00 00 d0 3f
0.200000 is 9a 99 99 99 99 99 c9 3f
0.166667 is 55 55 55 55 55 55 c5 3f
0.142857 is 92 24 49 92 24 49 c2 3f
0.125000 is 00 00 00 00 00 00 c0 3f
0.111111 is 1c c7 71 1c c7 71 bc 3f
0.100000 is 9a 99 99 99 99 99 b9 3f
0.090909 is 46 17 5d 74 d1 45 b7 3f
0.083333 is 55 55 55 55 55 55 b5 3f
0.076923 is 14 3b b1 13 3b b1 b3 3f
0.071429 is 92 24 49 92 24 49 b2 3f
0.066667 is 11 11 11 11 11 11 b1 3f
0.062500 is 00 00 00 00 00 00 b0 3f
0.058824 is 1e 1e 1e 1e 1e 1e ae 3f
0.055556 is 1c c7 71 1c c7 71 ac 3f
0.052632 is 28 af a1 bc 86 f2 aa 3f

Name: Anonymous 2007-05-21 2:32 ID:jkX0R5vu

>>32
Oh, without a doubt. "It's a decimal number! It's gotta be correct, right? Also, money types etc. are so slow!"...

Name: Anonymous 2007-05-21 14:13 ID:Ghoa89P/

money types??????

Name: Anonymous 2007-05-21 15:16 ID:Heaven

>>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: Anonymous 2007-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: Anonymous 2007-05-21 15:32 ID:5yYaqzBB

>Only enterprise languages have them as primitives.
fixed

Name: Anonymous 2007-05-21 15:34 ID:1bh/6waX

FUCKING JEWS STEAL MAH MONIES


KILL ALL JEWS

Name: Anonymous 2007-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.

Name: Anonymous 2007-05-21 21:42 ID:m6ZPJt7A

Wanna buy volcano insurance?

Name: Anonymous 2007-05-21 23:51 ID:Heaven

>>44
Sure, how much?

Name: Anonymous 2007-05-22 2:03 ID:Heaven

>>43
YHBT

Name: Anonymous 2009-01-14 14:48

</ThreadOver>

Name: Anonymous 2009-03-06 8:28


Available functions that can   help me cope?

Name: Anonymous 2010-12-17 1:20

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2011-02-04 16:41

Name: Sgt.Kabu槬㑎kimanレ펟 2012-05-29 1:57

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List