I don't see a problem with the C# rounding routine. AFAIR, C# doesn't offer a "round to {x} decimal places" and has a major gotcha in the official rounding routine.

Round isn't actually that bad. It's a way to replace C#'s default rounding "half towards even" with a more conventional "half towards up".

The real WTF is why would anyone want to use banker's rounding as a default method.
http://msdn.microsoft.com/en-us/library/aa340227(v=vs.71).aspx
http://en.wikipedia.org/wiki/Rounding#Round_half_to_even

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

If you're using floating point numbers in a financial application, you're doing it wrong.

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

If you're using floating point numbers in a financial application, you're doing it wrong.

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

You shouldn't use floating point for financial calculations. You always round to the nearest penny, in the [bank's|government's|company's] favor. In the case of the IRS, you round to the nearest dollar in the government's favor.

22.0f/3 was quite a common way of representing PI in a rough way before frameworks came long and stuck 'official' PI constants in.

In the India we using 22/7, no 22/3.

Thank you, come again!

The Christian bible states that PI is 3.

That's a load of SHEEIT. I'm certain that you never read the verses in question, but just repeated this fallacy-- so I'll ask you to read it for the first time.

22.0f/3 was quite a common way of representing PI in a rough way before frameworks came long and stuck 'official' PI constants in.

In the India we using 22/7, no 22/3.

Thank you, come again!

The Christian bible states that PI is 3. No floats needed back in those days I guess.

Well if you're going to pay any attention to that old thing, it also says Jesus walked on water. No floats needed for that either I suppose.

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

Please tell me this is a joke.

(Just in case it isn't: don't use floating point for financial crap)

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

22.0f/3 was quite a common way of representing PI in a rough way before frameworks came long and stuck 'official' PI constants in.

In the India we using 22/7, no 22/3.

Thank you, come again!

The Christian bible states that PI is 3. No floats needed back in those days I guess.

Well if you're going to pay any attention to that old thing, it also says Jesus walked on water. No floats needed for that either I suppose.

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

I disagree. Perhaps PI is not really constant throughout all time and positions in the infinite universe? Perhaps it is changing ever so slightly, so slow that in all of human history and in our galaxy, the change would be undetectable. At some point in time and space, it very well could be 3.

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

You shouldn't use floating point for financial calculations. You always round to the nearest penny, in the [bank's|government's|company's] favor. In the case of the IRS, you round to the nearest dollar in the government's favor.

The actual smallest unit of currency in the US is 1/10 of a cent. Just look at gas prices, they love charging 9/10 of a cent per gallon of gas.

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

I walk on water all the time. From late December to about March.

Even if we ignore the definition of the word "miracle", there are plausible circumstances in which a person could walk (or appear to walk) on water. But pi is a constant that will never be 3.

I disagree. Perhaps PI is not really constant throughout all time and positions in the infinite universe? Perhaps it is changing ever so slightly, so slow that in all of human history and in our galaxy, the change would be undetectable. At some point in time and space, it very well could be 3.

And that's one of the reasons that Texas will not implement Obamacare: we don't need the Federal Government telling us what PI is and how it should be calculated and what we are and are not allowed to do with our Mexican slaves.

The Christian bible states that PI is 3. No floats needed back in those days I guess.

I like how it's apparently more reasonable to invoke changing universal constants than it is to consider that the book might just have been describing a shitty engineer.

The Christian bible states that PI is 3. No floats needed back in those days I guess.

At the risk of being mildly serious: The Bible gives the measurements of a certain object, mentioning that the diameter is 10 and the circumference is 30.

(a) There is no such thing as an "exact measurement"; there is only measurement within a certain precision. This is commonly discussed in science classes under the heading "significant figures" -- feel free to google the phrase for details. As the quote is not from a scientific treatise but from a general discussion of the furniture in a certain building, the writer does not tell us the number of significant digits, but it's likely 2 or maybe only 1 (given that both numbers are multiples of ten). If you perform an arithemtic calculation on two numbers and the least accurate has only one significant digit, the answer is only meaningful to one significant digit. If the writer had said that he measured the circumference as 10 cubits accurate to 1 significant digit, and then concluded that the circumference was 31.42 cubits, he would have been marked wrong in my chemistry and physics classes.

Indeed, when I took chemistry in college, we had a question on a test that said you have a beaker with 40 g of water, you add .01 g of salt, what is the weight of the resultant mixture? The correct answer was 40 g. Students who wrote 40.01 g were marked wrong, because they had failed to understand the concept of significant figures.

In this case, 10 * 3.14159... = 30 -- one significant digit -- not 31.4159. You can't invent additional precision out of thin air.

(b) Even ignoring that this is a physical measurement and therefore inherently an approximation, pretending it's a question in abstract geometry, please tell me what you think the "correct" answer is. If you say 31, you are no better than the original writer: pi is no more equal to 3.1 than it is to 3. If you say 31.4, that's not an exact value for pi either. You could give 100 digits and it still wouldn't be exact. No matter how many digits you give, you will not be stating the exact value for pi. The only way to exactly state the value of pi is to say "pi" or give an algorithm. I suppose the writer could have said that the circumference was "10 times pi", but that just leaves it to the reader to do the calculation himself.

So you're ridiculing the Bible for, (a) failing to ignore the concept of significant figures, and (b) failing to ignore the fact that pi is a transcendental number. Apparently Moses understood science better than you do.

Perhaps the last file_exists encapsulation required a strict 0/1 type instead of a true/false return. You could do it in one line with type casting, but without knowing all the requirements, it could have been perfectly valid.

Pi in the bible, come on guys. This brillant bit comes from creationists:

‘And he [Hiram on behalf of King Solomon] made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about.’

So yes, 30 cubits / 10 cubits = 3. And now their Jesuit escape

If the actual diameter was 9.65 cubits, for example, this would have been reckoned as 10 cubits. The actual circumference would then have been 30.32 cubits. This would have been reckoned as 30 cubits (9.6 cubits diameter gives 30.14 circumference, and so on). The ratio of true circumference to true diameter would then have been 30.32÷ 9.65 = 3.14, the true value for pi, even though the measured value (i.e. to the nearest cubit) was 30 ÷ 10 = 3.

This comes from people who take the Bible literally. Is this bigotry the original WTF for which Jesus died at the cross?

Anyway, they do show us good use of the C# rounding routine in Biblical times...

Indeed, when I took chemistry in college, we had a question on a test that said you have a beaker with 40 g of water, you add .01 g of salt, what is the weight of the resultant mixture? The correct answer was 40 g.

That's how you know it was a chemistry question. If it had been a physics question the correct answer would have been 0.4N (assuming it to be in close proximity to the surface of the Earth).

Admin

22.0f/3 was quite a common way of representing PI in a rough way before frameworks came long and stuck 'official' PI constants in.

Admin

In the India we using 22/7, no 22/3.

Thank you, come again!

Admin

As far as pointless boolean synonyms go, "YOUBET" is a new one.

Admin

Admin

Admin

You can usually spot them by checking for anyone who is coding for web sites.

Admin

I like the graveyard of bad ideas. I might steal that.

Admin

I'd be willing to bet that this guy (gal?) got better grades in English class than in Math class.

Admin

I had a math teacher in middle school who (briefly) insisted that 22/7 is an exact representation of pi.

Perhaps she should have looked up what "irrational number" means...

Admin

almostgot it right. The correct advice is:Admin

Either that, or "355./113". It's only 1 character longer than "22.0f/3" and it's accurate to 6 decimal places.

Admin

Maybe.Gentlemen, we are within inches of developing the technology to properly handle True, False, FileNotFound.

Admin

The left out 'Yowzah!' as a possible TRUE value.

Admin

Admin

I don't see a problem with the C# rounding routine. AFAIR, C# doesn't offer a "round to {x} decimal places" and has a major gotcha in the official rounding routine.

Admin

Round isn't actually that bad. It's a way to replace C#'s default rounding "half towards even" with a more conventional "half towards up".

The real WTF is why would anyone want to use banker's rounding as a default method. http://msdn.microsoft.com/en-us/library/aa340227(v=vs.71).aspx http://en.wikipedia.org/wiki/Rounding#Round_half_to_even

Admin

Never has a comment on this site been more FileNotFound. You should be AdjectiveNotFound of yourself.

Admin

Yeah, apart from the missing '+' it seemed fairly reasonable to me. There are valid reasons for wanting to write your own rounding routine-- for example, in many financial applications, it is desirable to add something like 0.5000000001 instead of 0.5 to keep floating point error from causing the result of some calculations to round down erroneously.

Admin

Err...I come from a universe where different physical laws apply <shuffles away="" quietly=""><p> </shuffles>

Admin

When you're working with crazy stuff like PI, close enough has got to be good enough. You're never going to get it perfect.

And I mean never as in universe freezes solid type of never.

Admin

The filexists function can be explained by print statement debugging.

Admin

Admin

Admin

you're doing it wrong.Admin

use only oracle floats!

Admin

Admin

Not until the Deluge, at least. Heyo!

Admin

Nor today, if you have Prof. Frink teaching you: http://www.youtube.com/watch?v=O-Y-ua3WBi4

Admin

Admin

Admin

{"Maybe",

TIME[7]&1}I see no problem with the computer making a decision for you if you're waffling. This is a solid implementation of "Maybe."

Admin

Please tell me this is a joke.

(Just in case it isn't: don't use floating point for financial crap)

Admin

Admin

My Initial troll post finally wins.

Admin

Maybe is Prof. Alan Turing's engine. Read computer history to get knowledge like me.

Admin

I disagree. Perhaps PI is not really constant throughout all time and positions in the infinite universe? Perhaps it is changing ever so slightly, so slow that in all of human history and in our galaxy, the change would be undetectable. At some point in time and space, it very well could be 3.

Admin

Admin

To understand recursion, you must first understand recursion.

Admin

The code above actually has a typo. It should read "YOUBETCHA" instead of "YOUBET". It was part of the Minnesota release.

Admin

I walk on water all the time. From late December to about March.

Admin

Ooh, I know how to fix this code. Works as advertised:

// Convert to negative number

varInt := StrToInt('-1');

Admin

And that's one of the reasons that Texas will not implement Obamacare: we don't need the Federal Government telling us what PI is and how it should be calculated and what we are and are not allowed to do with our Mexican slaves.

Admin

With the boolean table, can a jokey Easter egg be considered a WTF? Personally I live the implementation of maybe.

The round function is just fine. And you may indeed find uses for floats in financial software, some of them may even be legal!

Admin

You can get this code to fail:

Simply pass in "null".

Admin

x=atan(1)*4

is perfect!

Admin

I like how it's apparently more reasonable to invoke changing universal constants than it is to consider that the book might just have been describing a shitty engineer.

Admin

At the risk of being mildly serious: The Bible gives the measurements of a certain object, mentioning that the diameter is 10 and the circumference is 30.

(a) There is no such thing as an "exact measurement"; there is only measurement within a certain precision. This is commonly discussed in science classes under the heading "significant figures" -- feel free to google the phrase for details. As the quote is not from a scientific treatise but from a general discussion of the furniture in a certain building, the writer does not tell us the number of significant digits, but it's likely 2 or maybe only 1 (given that both numbers are multiples of ten). If you perform an arithemtic calculation on two numbers and the least accurate has only one significant digit, the answer is only meaningful to one significant digit. If the writer had said that he measured the circumference as 10 cubits accurate to 1 significant digit, and then concluded that the circumference was 31.42 cubits, he would have been marked wrong in my chemistry and physics classes.

Indeed, when I took chemistry in college, we had a question on a test that said you have a beaker with 40 g of water, you add .01 g of salt, what is the weight of the resultant mixture? The correct answer was 40 g. Students who wrote 40.01 g were marked wrong, because they had failed to understand the concept of significant figures.

In this case, 10 * 3.14159... = 30 -- one significant digit -- not 31.4159. You can't invent additional precision out of thin air.

(b) Even ignoring that this is a physical measurement and therefore inherently an approximation, pretending it's a question in abstract geometry, please tell me what you think the "correct" answer is. If you say 31, you are no better than the original writer: pi is no more equal to 3.1 than it is to 3. If you say 31.4, that's not an exact value for pi either. You could give 100 digits and it still wouldn't be exact. No matter how many digits you give, you will not be stating the exact value for pi. The only way to exactly state the value of pi is to say "pi" or give an algorithm. I suppose the writer could have said that the circumference was "10 times pi", but that just leaves it to the reader to do the calculation himself.

So you're ridiculing the Bible for, (a) failing to ignore the concept of significant figures, and (b) failing to ignore the fact that pi is a transcendental number. Apparently Moses understood science better than you do.

Admin

Perhaps the last file_exists encapsulation required a strict 0/1 type instead of a true/false return. You could do it in one line with type casting, but without knowing all the requirements, it could have been perfectly valid.

Admin

Pi in the bible, come on guys. This brillant bit comes from creationists:

So yes, 30 cubits / 10 cubits = 3. And now their Jesuit escape This comes from people who take the Bible literally. Is this bigotry the original WTF for which Jesus died at the cross?Anyway, they do show us good use of the C# rounding routine in Biblical times...

Admin