The Object Test, a New PI, and More SHEEIT

« Return to Article
  • PZ 2012-07-09 11:22
    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.
  • Nagesh 2012-07-09 11:29
    PZ:
    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!
  • Chronomium 2012-07-09 11:33
    As far as pointless boolean synonyms go, "YOUBET" is a new one.
  • KattMan 2012-07-09 11:34
    Nagesh:
    PZ:
    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.
  • Nagesh 2012-07-09 11:41

    public static int getNegativeOfNumber ( int num )
    {
    int absolueValue=Math.abs(num) ;
    int negativeInt=-1*absolueValue ;
    return negativeInt;
    }
  • Jerry 2012-07-09 11:50
    variable will hold its value across different browser instances
    There are a lot of people out there who have no business coding for web sites.

    You can usually spot them by checking for anyone who is coding for web sites.
  • Pavel 2012-07-09 11:50
    I like the graveyard of bad ideas. I might steal that.
  • C-Derb 2012-07-09 11:52

    // Convert to negative number
    varInt := StrToInt('-' + IntToStr(varInt));

    I'd be willing to bet that this guy (gal?) got better grades in English class than in Math class.
  • Kef Schecter 2012-07-09 11:54
    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...
  • Ralph 2012-07-09 11:54
    Save your work and restart Visual Studio.
    This message almost got it right. The correct advice is:
    Save your work: don't use Visual Studio.
  • Ken B. 2012-07-09 11:55
    PZ:
    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.
    Given that it's only accurate to 2 decimal places, I would think hard-coding "3.14" would be easier.

    Either that, or "355./113". It's only 1 character longer than "22.0f/3" and it's accurate to 6 decimal places.
  • Paul 2012-07-09 11:57
    {"Maybe",__TIME__[7]&1}
    C'mon, is this for real? I guess you gotta love a boolean that successfully implements Maybe.

    Gentlemen, we are within inches of developing the technology to properly handle True, False, FileNotFound.
  • Glenn Lasher 2012-07-09 12:01
    The left out 'Yowzah!' as a possible TRUE value.
  • Steve The Cynic 2012-07-09 12:05
    C-Derb:

    // Convert to negative number
    varInt := StrToInt('-' + IntToStr(varInt));

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

    Probably, but I worry a little about what happens if the number was already negative... What does StrToInt do with "--7"?
  • Shaftway 2012-07-09 12:11
    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.
  • Kaniu 2012-07-09 12:14
    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
  • XXXXX 2012-07-09 12:15
    Paul:
    {"Maybe",__TIME__[7]&1}
    C'mon, is this for real? I guess you gotta love a boolean that successfully implements Maybe.

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


    Never has a comment on this site been more FileNotFound. You should be AdjectiveNotFound of yourself.
  • Anonymous Genius 2012-07-09 12:16
    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.
  • PZ 2012-07-09 12:22
    Nagesh:
    PZ:
    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!


    Err...I come from a universe where different physical laws apply <shuffles away quietly>
  • Sagan 2012-07-09 12:25
    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.
  • Reinier 2012-07-09 12:28
    The filexists function can be explained by print statement debugging.
  • Fred 2012-07-09 12:28
    function filexists($file) {
    ...
    if(file_exists($file))...
    My Java teacher (who was an accountant, not a computer geek) said we had to do this. Encapsulation or something like that.
  • Pastor Eyes 2012-07-09 12:31
    KattMan:
    Nagesh:
    PZ:
    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.
  • History Teacher 2012-07-09 12:44
    Anonymous Genius:
    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.
  • Nagesh 2012-07-09 12:47
    History Teacher:
    Anonymous Genius:
    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.


    use only oracle floats!
  • Some Damn Yank 2012-07-09 12:53
    Anonymous Genius:
    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.
  • Jonathan Hamilton 2012-07-09 12:56
    KattMan:
    The Christian bible states that PI is 3. No floats needed back in those days I guess.


    Not until the Deluge, at least. Heyo!
  • pedagogical pedant 2012-07-09 13:16
    KattMan:
    Nagesh:
    PZ:
    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.


    Nor today, if you have Prof. Frink teaching you: http://www.youtube.com/watch?v=O-Y-ua3WBi4
  • operagost 2012-07-09 13:20
    KattMan:
    Nagesh:
    PZ:
    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.
  • operagost 2012-07-09 13:22
    Pastor Eyes:
    KattMan:
    Nagesh:
    PZ:
    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.
  • ShatteredArm 2012-07-09 13:26
    {"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."
  • Kef Schecter 2012-07-09 13:29
    Anonymous Genius:
    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)
  • Zylon 2012-07-09 13:30
    operagost:
    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.

    Thank you, Buzz Killington.
  • KattMan 2012-07-09 13:30
    operagost:
    Pastor Eyes:
    KattMan:
    Nagesh:
    PZ:
    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.


    My Initial troll post finally wins.
  • Nagesh 2012-07-09 13:30
    Maybe is Prof. Alan Turing's engine. Read computer history to get knowledge like me.
  • Infinite Time and Space 2012-07-09 13:42
    operagost:

    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.
  • Anketam 2012-07-09 13:43
    Some Damn Yank:
    Anonymous Genius:
    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.
  • Anketam 2012-07-09 13:45
    Pavel:
    I like the graveyard of bad ideas. I might steal that.
    I think you should put that idea in your graveyard.

    _______________________________


    To understand recursion, you must first understand recursion.
  • wonk 2012-07-09 13:52
    The code above actually has a typo. It should read "YOUBETCHA" instead of "YOUBET". It was part of the Minnesota release.
  • Canada Eh? 2012-07-09 13:55
    operagost:


    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.
  • Tristram 2012-07-09 13:59
    Ooh, I know how to fix this code. Works as advertised:

    // Convert to negative number

    varInt := StrToInt('-1');
  • Born Texas Proud 2012-07-09 14:03
    Infinite Time and Space:
    operagost:

    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.
  • dogmatic 2012-07-09 14:03
    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!
  • Heinz 2012-07-09 14:06
    You can get this code to fail:



    /**
    * Tests if {@link XXXX} class extends {@link Object} class.
    */
    @Test
    public void testInheritance() {
    Assert.assertTrue("Class does not extends Object class.",
    instance instanceof Object);
    }



    Simply pass in "null".
  • Frank 2012-07-09 14:25
    x=atan(1)*4

    is perfect!
  • Jinren 2012-07-09 14:31
    KattMan:
    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.
  • Jay 2012-07-09 14:38
    KattMan:
    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.
  • Willie 2012-07-09 14:41
    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.
  • TGV 2012-07-09 14:43
    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...
  • pjt33 2012-07-09 14:50
    Jay:
    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).
  • Nagesh 2012-07-09 14:55
    pjt33:
    Jay:
    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).


    Are not good scales available in your country?
  • Sayer 2012-07-09 15:00
    That second explanation makes sense. Also, if you want to make fun of people who literally interpret the bible there are lots of other examples that could have been chosen that wouldn't also have made you look like an idiot.
  • Ninkasi 2012-07-09 15:14
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.
  • Born Texas Proud 2012-07-09 15:17
    Nagesh:
    pjt33:
    Jay:
    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).


    Are not good scales available in your country?

    Yes
  • Oak 2012-07-09 15:18
    Infinite Time and Space:
    operagost:

    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.


    You are confusing physical constants - such as the speed of light- which theoretically could change, with mathematical constants - such as pi - which are completely independent from the universe. Pi cannot change.
  • Anonymous 2012-07-09 15:19
    Heinz:
    You can get this code to fail:



    /**
    * Tests if {@link XXXX} class extends {@link Object} class.
    */
    @Test
    public void testInheritance() {
    Assert.assertTrue("Class does not extends Object class.",
    instance instanceof Object);
    }



    Simply pass in "null".


    That's not inheritance; that's instantiation. So the WTF stands.
  • BillClintonIsTheMan 2012-07-09 15:23
    Boolean is missing the south jersey "yeh" and "nawh"
  • Andrew 2012-07-09 15:25
    pjt33:
    Jay:
    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).
    If an atomic physicist had answered it, the answer would be given in electron-volts. Still don't understand those buggers (the measurement and those people).
  • Paul Carter 2012-07-09 15:25
    Infinite Time and Space:


    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.


    Bzzt! Try again.

    PI is a mathematical constant. It's not a physical property of the universe. It's like saying that 1 + 1 might equal 3 in the future.
  • null 2012-07-09 15:26
    public static int getNegativeOfNumber ( int num )

    {
    if (num > 0)
    {return -1*num}
    else
    {return num}
    }
  • Sayer 2012-07-09 15:31
    Ninkasi:
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.


    Or we can assume that the dude writing the passage was a scribe and not a fucking engineer - therefore making any inaccuracies in reporting the measurement hardly surprising or noteworthy.
  • Nagesh 2012-07-09 15:41
    null:
    public static int getNegativeOfNumber ( int num )

    {
    if (num > 0)
    {return -1*num}
    else
    {return num}
    }

    U ain't remembering to put in semi-colons.
  • Nagesh 2012-07-09 15:42
    Also

    Nagesh:
    null:
    public static int getNegativeOfNumber ( int num )
    {
    return num > 0 ? num * -1 : num;
    }

    U ain't remembering to put in semi-colons.
  • Meep 2012-07-09 16:00
    If you draw a line segment from the center of a unit circle to some point on the circle at theta degrees, and then draw a right triangle to show the rise and run of that segment, cosine is the run and sine is the rise, and tangent is the slope, slope being rise / run, tan is sine / cosine.

    Since 360 degrees = 2pi radians, 45 degrees is pi/4 radians, and a line at 45 degrees has a slope of 1. So tan(pi/4) = 1, solving for pi we get:

    pi = 4 * arctan(1)

    That's usually the best way to get pi if you have the relatively common arctan function. It's also a good way to test if your trig functions are broken...
  • emurphy 2012-07-09 16:02
    Kaniu:
    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


    Because the industry standard has said so for upwards of 25 years?
    http://en.wikipedia.org/wiki/IEEE_floating_point#Rounding_rules

    Of course, industry standards can be WTFs too, but this one makes sense because the sum of rounded figures (assuming they're fairly evenly distributed) is closer to the sum of unrounded figures.

    Simple example: You need to output 10,000 positive dollar amounts, which for whatever reason need to be individually rounded to the nearest dollar. 500 of them are $(something).50, of which 256 of them are $12.50 and 244 of them are $11.50 (so the sum of those 500 transactions without rounding is $6,006).

    If you use round-half-toward-even, then you end up with $6,000. If you use round-half-up, then you end up with $6,500.

    In theory, you could hit $6,006 exactly by going back and arbitrarily selecting 6 of the $12.50 amounts to round up, but that's usually considered more trouble than it's worth. (I did have at least one project where the client wanted to hit the target exactly; I ended up arbitrarily selecting the last transaction and fudging it by whatever amount it took, which the client considered acceptable.)
  • D-Coder 2012-07-09 16:07
    Sayer:
    Ninkasi:
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.


    Or we can assume that the dude writing the passage was a scribe and not a fucking engineer - therefore making any inaccuracies in reporting the measurement hardly surprising or noteworthy.
    Of course. Unless the base assumption is that the Bible is literally true. In which case you're a heretic.

    Oh and let me be the first to point out that this is not the Christian bible, but the Hebrew bible, and you may send my pedantry points to me at your convenience.
  • KattMan 2012-07-09 16:09
    Sayer:
    Ninkasi:
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.


    Or we can assume that the dude writing the passage was a scribe and not a fucking engineer - therefore making any inaccuracies in reporting the measurement hardly surprising or noteworthy.


    And my troll post is still winning.
    And yes this is a good way to show that the bible was written by man and not God. It's a history book written by religious people, the events did happen as they see it, but the interpretation is left up to the reader, hence why faith is important.
  • Whosdr 2012-07-09 16:10
    Any real computer or maths buff should know Pi is roughly 3.14159265358979323846264338327950288419716939937510582097494492307.
    Come on, is it really that hard to remember?
  • R. Bolla 2012-07-09 16:11
    Canada Eh?:
    I walk on water all the time. From late December to about March.

    Make up your mind.
  • jaloopa 2012-07-09 16:17
    jaloopauser="Paul Carter"][quote user="Infinite Time and Space"]

    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.[/quote]

    Bzzt! Try again.

    PI is a mathematical constant. It's not a physical property of the universe. It's like saying that 1 + 1 might equal 3 in the future.[/quote]

    Actually, if you define pi as the ratio of a circle's radius and circumference then it only equals the commonly accepted value in Euclidean flat space. In a curved spacetime it is different
  • justsomedude 2012-07-09 16:21
    Jay:
    Apparently Moses understood science better than you do.


    Are you saying Moses wrote that part?
  • Chelloveck 2012-07-09 16:22
    [quote user="Paul Carter"][quote user="Infinite Time and Space"]PI is a mathematical constant. It's not a physical property of the universe. It's like saying that 1 + 1 might equal 3 in the future.[/quote]

    Only if you assume flat spacetime. One could easily construct a circle which has a measured ratio of circumference to diameter equal to exactly 3.00(bar) if one does so on an appropriately curved spacetime manifold. I leave proof-by-demonstration as an exercise for the student.
  • AGray 2012-07-09 16:23
    For the negative number problem, based on the code given, it sounds like the method is required to only output a negative number. So, I would think something like this would fulfill the requirement:

    public double GetNegative(double given)
    
    {
    if(given < 0) return given;

    return -1 * given;
    }


    I use multiplication, because in a conversation about this very WTF, I learned that there are cases where multiplication is actually faster than just 0-x!

    CAPTCHA: jumentum - It's like Jumanji, with momentum!
  • justsomedude 2012-07-09 16:23
    pjt33:

    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).


    N is a measure of force, the question was about weight. If you had been in a physics test you would have got that one wrong.
  • AGray 2012-07-09 16:28
    AGray:
    public double GetNegative(double given)
    
    {
    if(given < 0) return given;

    return -1 * given;
    }



    Actually, I could've done it better:

    return (given < 0) ? given : -1 * given;


    I am the WTF! :O
  • C-Derb 2012-07-09 16:37
    Anketam:
    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.

    This is TRWTF. When are gas stations going to drop the ridiculous 9/10 of a cent pricing scheme?

    Back in 1950 you could fool people into thinking $.57 9/10 is 3 cents cheaper than $.60 because saving three dimes on your 20 gallon fill up meant something. But today it's going to take at least a two dime difference per gallon to get me to go across the street for some gas.

    When there is a 3 or 4 or 5 on the left side of the decimal point, you need to drop the silly 9/10 of a cent charade.
  • Jeff Dege 2012-07-09 16:38
    There are an infinite number of possible systems of mathematical notation in which 22/7 is an exact representation of PI.

    None of them, however, are in common use.
  • n/a 2012-07-09 16:42
    justsomedude:
    pjt33:

    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).


    N is a measure of force, the question was about weight. If you had been in a physics test you would have got that one wrong.


    Weight is a force. Mass is not (in conventional sense).
  • TGV 2012-07-09 16:48
    Sayer:
    Or we can assume that the dude writing the passage was a scribe and not a fucking engineer - therefore making any inaccuracies in reporting the measurement hardly surprising or noteworthy.

    Someone's getting upset and using ugly words that have been forbidden by his god, or rather, the people that claim to be the representatives of his deity of preference.

    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.
  • Jeff 2012-07-09 17:01
    KattMan:
    faith is TRWTF
    FTFY
  • adam 2012-07-09 17:04
    i really, really, REALLY hope Andy P doesn't work for NASA, any engineering firm, or any engineering software firm.
  • mathematician 2012-07-09 17:12
    Paul Carter:
    Infinite Time and Space:


    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.


    Bzzt! Try again.

    PI is a mathematical constant. It's not a physical property of the universe. It's like saying that 1 + 1 might equal 3 in the future.


    1+1=3 is certainly true in a given magma (M,+) where the operator + is defined as +: a+b+1 for all a,b in M.

    So no, it's not like saying that. The rest of your comment is correct.
  • Captcha:transverbero 2012-07-09 17:12
    const float tau = (44.0f/7);

    There, fixed!
  • Nagesh 2012-07-09 17:13
    TGV:
    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.
    I don't. You got a problem with that?

    But even so, the literal meaning of "thirty cubits" is not "30.0 cubits exactly". None of the extant manuscript include the word "exactly" (or rather, any words in the original language, probably biblical Hebrew, that would support such a translation). There is no reason to exist any such manuscript ever existed.

    Taking something "literally" includes, by definition, refraining from injecting any meaning into it that isn't there, such as your insistence on a spurious assumption of mathematical exactness.
  • Jamal 2012-07-09 17:17
    Nagesh:

    public static int getNegativeOfNumber ( int num )
    {
    int absolueValue=Math.abs(num) ;
    int negativeInt=-1*absolueValue ;
    return negativeInt;
    }

    Remember: it is always praferrable to put the inside of the function in one line to spend less space and make the client happy:


    public static int getNegativeOfNumber ( int num )
    {
    return -1*Math.abs(num);
    }
  • Tud 2012-07-09 17:27
    TGV:
    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.

    I am not exactly a devout christian, but that's just false. There is no exact border that separates "literally" from "non-literally". Words are just pointers to fuzzy concepts, even without taking into account that they are stored inside brains and their values differ from person to person (apply that to both the word "literally" and the contents of the Bible).
  • zac 2012-07-09 17:27
    Still ignoring positive and negative zero...
  • Dave 2012-07-09 17:28
    operagost:
    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.

    I walked across the river Thames last week. Didn't even get wet.

    Useful things, bridges.
  • Herohtar 2012-07-09 17:28
    I was expecting one of the first comments to be a "GRAVEYARD OF BAD COMMENTS" marker. I am greatly disappointed.
  • PiisAWheeL 2012-07-09 17:30
    XXXXX:
    Paul:
    {"Maybe",__TIME__[7]&1}
    C'mon, is this for real? I guess you gotta love a boolean that successfully implements Maybe.

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


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

    Anketam:
    Some Damn Yank:
    Anonymous Genius:
    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.
    Actually, if you've ever purchased penny stocks, you can buy stock for .0001 Cents, or 1/100th of a penny.

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

    // Convert to negative number

    varInt := StrToInt('-1');
    That fails on an input below 0.
  • Anon 2012-07-09 17:31
    Sucker you fell for a myth.
  • SG_01 2012-07-09 17:52
    ShatteredArm:
    {"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."


    I agree, though I would personally prefer a solution that defines the uncertainty at run-time rather than compile-time.
  • DarrenC 2012-07-09 17:56
    operagost:
    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.


    In Pinary, the value of pi is 1.0
  • n_slash_a 2012-07-09 17:57
    Whosdr:
    Any real computer or maths buff should know Pi is roughly 3.14159265358979323846264338327950288419716939937510582097494492307.
    Come on, is it really that hard to remember?

    +1
  • sdfdh 2012-07-09 18:03
    Nagesh:
    PZ:
    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!

    @PZ Why would people use 22/7 before any official 'PI' constant?
    When I was a wee tacker, we used to round to 3.142 and I'd be surprised if most people who have ever had to use PI for anything would probably use 3.142 or even better resolution (eg 3.14159). Given 22/7 (3.1428571....) rounds to 3.143 it's simply the wrong value to use....

    And given that the more mathematical we geeks get the more pedantic about accuracy we are, I'm sure the peeps using Pi way back when would have preferred to explicitly use something like 3.141592653589793 (even though I'm near certain that would get truncated)

    22/7 is fine for primary school kids who want to work out the perimeter of circle then measure it with a piece of string to see that it was correct, but I'm not sure it's even close to an adequate estimate of Pi for any other reason....

    Maybe they should have had 21.99115848/7
  • God 2012-07-09 18:04
    KattMan:
    Nagesh:
    PZ:
    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.
    No it doesn't.
  • Hello Operator 2012-07-09 18:14
    operagost:
    Pastor Eyes:
    KattMan:
    Nagesh:
    PZ:
    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.
    Ah yes....
    The Mathematician says that PI is approximately:
    3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
    The Computer Scientist says that Pi is exactly 3.14
    The Physicist says that pi is a number somewhere around 3 whose precise value is not important and can be calculated to whatever accuracy needed as needed, provided people understand why we use it in these claculations.
    The Baker is sick of Pi....
  • Johnny McGraw 2012-07-09 18:20
    Jay:
    KattMan:
    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.
    I think the word pi was lost in translation because the non-aramaic speaking world didn't have a word for it yet...

    Also, given they didn't have computers back then, let alone very accurate measuring devices, I think we can accept that 3 was about as accurate as Pi was going to get - but I guess this ties in with your rant about signifcant figures. Apparently Alan Turing was one of them....
  • soe i;ghs.d 2012-07-09 18:38
    Ninkasi:
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.
    I think I found your problem....
  • Some Damn Yank 2012-07-09 18:43
    C-Derb:
    Back in 1950 you could fool people into thinking $.57 9/10 is 3 cents cheaper than $.60 because saving three dimes on your 20 gallon fill up meant something. But today it's going to take at least a two dime difference per gallon to get me to go across the street for some gas.
    Back in 1950, if you charged $0.579/gal you'd better be someplace like Death Valley or you'd be the laughingstock of the town. I was paying $0.199/gal in 1972. Then the Shaw needed money to buy weapons from the USA so Kissinger told him to charge more for oil and the rest is history, but I digress.
  • Mr.'; Drop Database -- 2012-07-09 18:53
    Ken B.:
    PZ:
    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.
    Given that it's only accurate to 2 decimal places, I would think hard-coding "3.14" would be easier.

    Either that, or "355./113". It's only 1 character longer than "22.0f/3" and it's accurate to 6 decimal places.
    4*atan(1) is one character longer again and is as accurate as your floating-point representation.
  • Exxon 2012-07-09 19:06
    C-Derb:
    Anketam:
    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.

    This is TRWTF. When are gas stations going to drop the ridiculous 9/10 of a cent pricing scheme?

    Back in 1950 you could fool people into thinking $.57 9/10 is 3 cents cheaper than $.60 because saving three dimes on your 20 gallon fill up meant something. But today it's going to take at least a two dime difference per gallon to get me to go across the street for some gas.

    When there is a 3 or 4 or 5 on the left side of the decimal point, you need to drop the silly 9/10 of a cent charade.
    It's to make calculation harder when people try to work out 6c a gallon discounts
  • Methuzzella 2012-07-09 19:16
    Tud:
    TGV:
    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.

    I am not exactly a devout christian, but that's just false. There is no exact border that separates "literally" from "non-literally". Words are just pointers to fuzzy concepts, even without taking into account that they are stored inside brains and their values differ from person to person (apply that to both the word "literally" and the contents of the Bible).
    And I increasingly get the impression that the only people in the world who seem to think the Old Testament is anything even remotely literal are the people who want to argue that Science is right and the bible is wrong and never the twain shall meet.

    Even if the bible (OT) were literal, it has undergone much translation often from languages that could express concepts that we can't (or at least don't). The very beginning of the bible is a case in point: "On the first day God created day and night"
    Well I'll be damned. Surely the day must already have existed if this was the first day? Sounds like the Big Bang. In the first instant, the universe began.
    Following that we have now shown "first day" does not literally mean "first day". Extrapolating this to the other six "days" we can actually lead ourselves to believe that Genesis is not entirely inconsistent with the whole idea of evolution. Good heavens, who'd have thunk it?

    Concize version: The bible (Old Testament) is a series of fables not facts. Taken in this context it is clear that Religion and Science don't necessarily have to disagree. I'm sure a lot of scientists will be disappointed (apologies to scientists that aren't, but in my experience it's the science voice attacking the religious voice not the other way around - although I would very much expect it to flow the opposite way)
  • Dromedary 2012-07-09 19:38
    Nikola Tesla is a genius
    http://theoatmeal.com/comics/tesla
  • Gerry 2012-07-09 20:00
    Steve The Cynic:
    C-Derb:

    // Convert to negative number
    varInt := StrToInt('-' + IntToStr(varInt));

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

    Probably, but I worry a little about what happens if the number was already negative... What does StrToInt do with "--7"?


    Fail miserably of course:
    ---------------------------
    Debugger Exception Notification
    ---------------------------
    Project Project1.exe raised exception class EConvertError with message '''--7'' is not a valid integer value'.
    ---------------------------
    Break Continue Help
    ---------------------------
  • Mike 2012-07-09 21:04
    The testInheritance thing just looks like somebody was learning the language and forgot to remove a piece of experimental code.
  • Squeeself 2012-07-09 21:08
    Yup, soon will come a day when code magics itself into existence without a compiler:

    {"FileNotFound", !__FILE__}
  • RichP 2012-07-09 21:38
    Close. It's:

    #define YASURE 1

    for the Minnesota edition.
  • Troy 2012-07-09 22:56
    Redefining addition, does not make him wrong. It makes you look silly. Especially since you have defined addition in a recursive manner.
  • Jesus 2012-07-09 23:45
    I say unto thee, thou shalt accept the value of pi as acos(-1).
  • nomdeplume 2012-07-10 00:43
    I feel like the first one should be:

    // Hi, I'm a web developer. I have no idea how the web works. Wish me luck!
  • Jim In Texas 2012-07-10 01:19
    "Rabbi Belaga presents the following explanation: The Hebrew word for line or circumference is written in the Bible as a 3 letter Hebrew word transliterated as kaveh, and whose equivalent English letters are KVH (kof, vav, hei). Yet, that word is read as a 2 letter Hebrew word whose equivalent English letters are KV.

    Hebrew letters have numerical values, and the letters in question have values kof = 100, vav = 6, and hei = 5. So KVH = 100 + 6 + 5 = 111, and KV = 100 + 6 = 106. The ratio of KVH to KV is 111/106, which when multiplied by the value of 3 that was implied by 1 Kings 7:23, gives 3.141509 (rounded), which is again pretty close to pi. "

    http://jerry.praxisiimath.com/pi.html
  • David Martensson 2012-07-10 02:22
    // Apparently, in at least on situation, a Statically declared public
    // variable will hold its value across different browser instances making calls to the
    // same web page.
    // For now, reset these variables on Page_PreInit.

    In C# at least static properties keep their value until the application domain is reset, which is not done on a per session basis.

    So any static properties will share its value between concurrent and all other sessions handled by the same appdomain, and since an appdomain can live for hours or more that could be a lot of sessions.

    Unfortunately, not every book on C# for the web mentions this little gem making this a fairly common problem for new coders until they stumble on it on their own, I have seen it a few times with new coders here :/
  • Mick 2012-07-10 02:44
    Jay wrote: "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."

    Well, the bible also says that rabbits are rumiants and that grasshoppers have 4 legs. Frankly, there are many things in the bible to laugh at. I guess that the creation of the known universe in 7 days is also a clear instance of failure to grasp the concept of exactitude and/or precision...
    As a source of technical/scientific knowledge, the bible (or the quran, or the torah, or the kavalah or the whatever sacred text you can think of that is a revelation) is as good as News of the World.
  • Ton 2012-07-10 02:46
    However, if the "a" key on your keyboard is broken, you can use pi= 22./7 + sin( 22./7 ). It has an error of 1 in 10^10.
  • Braindead 2012-07-10 02:47
    Damn, they sold me a bible without #define statements!
    I hate when gods don't use #define in their sacred books!
  • Modern believer in scientology 2012-07-10 03:10
    Methuzella wrote:
    "And I increasingly get the impression that the only people in the world who seem to think the Old Testament is anything even remotely literal are the people who want to argue that Science is right and the bible is wrong and never the twain shall meet."

    Well, just exclude christian fundamentalists and all the americans who in surveys declare that they think that everything described in the bible is true, that evolution is false, and you got it...
    Sacred books of revelation and science cannot meet because revelations are about revealed truths that must be accepted without thinking, while science is about facts and critical thinking. A revelation is written in stone, while science is constantly evolving as theories must improve to reflect correctly the facts of the physical world.
    But I am glad to know that the bible is not to be taken literally, I guess this means that sins are metaphoric expressions of moral advices, there's no hell and even the concept of soul might be a simple beautification of the idea of human nature.
    So good to know that the ten commandments are just metaphoric ideas, so I cn actually understand them as I see fit, which after all what all military chaplains have been doing when it comes to the "thou shalt not kill" thingy, since blessing men who are going to kill other men doesn't seem quite a christian idea... But luckily we are XXI century people, and we don't hold irrational beliefs and superstitious ideas.

    captcha: ideo, I create anything with my imagination and make it come true
  • Planar 2012-07-10 03:17
    Infinite Time and Space:

    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.


    You've got it wrong. The value of PI has nothing to do with time or space, it is a mathematical constant. If you want to change the value of PI, you'll have to change the value of some integers, because of PI is defined by a number of formulas that depend only on natural numbers, for example:

    PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...

    see http://en.wikipedia.org/wiki/Pi for more formulas of the same kind.
  • twigg 2012-07-10 03:24

    /**
    * Tests if {@link XXXX} class extends {@link Object} class.
    */
    @Test
    public void testInheritance() {
    Assert.assertTrue("Class does not extends Object class.",
    instance instanceof Object);
    }



    This is generated code.

    There are unit test generators for simple classes (think JavaBeans).

    They make managers happy, as unit test code coverage goes up, while developers don't have to waste time on testing getters and setters.

    Kind of a WTF on it's own...
  • chrismcb 2012-07-10 03:44
    justsomedude:

    N is a measure of force, the question was about weight. If you had been in a physics test you would have got that one wrong.


    What do you think weight is?

    Of course I believe the original question was about mass not weight.
  • Steve The Cynic 2012-07-10 04:06
    Dave:
    operagost:
    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.

    I walked across the river Thames last week. Didn't even get wet.

    Useful things, bridges.

    You crossed the Thames, therefore you were in England, therefore it rained on you, so unless you had an umbrella, you got wet.
  • Steve The Cynic 2012-07-10 04:08
    DarrenC:
    operagost:
    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.


    In Pinary, the value of pi is 1.0

    No, in Pinary ("base pi"), the value of pi is pi. It is written as 10.
  • cousteau 2012-07-10 04:23
    What a bunch of boole sheeit
    ake.
  • beginner_ 2012-07-10 04:31
    Nagesh:
    pjt33:
    Jay:
    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).


    Are not good scales available in your country?


    Agree. Doesn't need a special scale to measure that difference. Any half-decent lab scale can do so. it's pretty easy actual so bad example. I would have written 40.01 g and if I failed because of that I would've went to proof experimentally how stupid that question was. They should have chosen a 1 liter of water (= 1 kg which also test if the students are proficient in the metric system :P).
  • Gurth 2012-07-10 04:41
    Jinren:
    KattMan:
    The Christian bible states that PI is 3.


    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.

    Or B.S. Johnson.
  • Cbuttius 2012-07-10 04:47
    Steve The Cynic:
    C-Derb:

    // Convert to negative number
    varInt := StrToInt('-' + IntToStr(varInt));

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

    Probably, but I worry a little about what happens if the number was already negative... What does StrToInt do with "--7"?


    In C++ at least if you try --7 you will get a compiler error "7 is not an l-value" or similar.
  • Gurth 2012-07-10 04:54
    Ninkasi:
    Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    Or it could be that the reason it's no longer standing is because it was destroyed on purpose:
    http://en.wikipedia.org/wiki/Temple_of_Solomon:
    The Temple was plundered by the Babylonian king Nebuchadnezzar when the Babylonians attacked Jerusalem during the brief reign of Jehoiachin c. 598 (2 Kings 24:13), Josiah's grandson. A decade later, Nebuchadnezzar again besieged Jerusalem and after 30 months finally breached the city walls in 587 BCE, subsequently burning the Temple, along with most of the city (2 Kings 25). According to Jewish tradition, the Temple was destroyed on Tisha B'Av, the 9th day of Av (Hebrew calendar).
  • Cbuttius 2012-07-10 05:00
    the real WTF is posters here who think the book of Kings is a "Christian" book.
  • Cbuttius 2012-07-10 05:50
    Exxon:
    C-Derb:
    Anketam:
    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.

    This is TRWTF. When are gas stations going to drop the ridiculous 9/10 of a cent pricing scheme?

    Back in 1950 you could fool people into thinking $.57 9/10 is 3 cents cheaper than $.60 because saving three dimes on your 20 gallon fill up meant something. But today it's going to take at least a two dime difference per gallon to get me to go across the street for some gas.

    When there is a 3 or 4 or 5 on the left side of the decimal point, you need to drop the silly 9/10 of a cent charade.
    It's to make calculation harder when people try to work out 6c a gallon discounts


    The intention is that you don't buy this commodity in single units therefore you never pay the actual unit price.

    Stock is commonly listed in fractions of a penny - on the London Stock Exchange a tick is actually a quarter of a penny. But as you don't buy them in ones, you never actually spend a quarter of a penny.

    Petrol in the UK is at the moment around £1.299 a litre so if you fill your car with 50L you will pay £64.95 rather than £65 you would pay if the price was listed at £1.30

    Yes, it's "only" 5p but it is an amount in legal tender.

  • Vitus 2012-07-10 06:20
    Oak:
    Infinite Time and Space:
    operagost:

    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.


    Wrong. Pi is dependent on the curvature of space. In a largely flat space it is what we measure it to be. In a rather curved space you will find it smaller or bigger depending on the type curvature. In the early universe it would have been much smaller so there was a time when it was 3

    You are confusing physical constants - such as the speed of light- which theoretically could change, with mathematical constants - such as pi - which are completely independent from the universe. Pi cannot change.
  • Vitus 2012-07-10 06:24
    Oak:
    Infinite Time and Space:
    operagost:

    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.


    You are confusing physical constants - such as the speed of light- which theoretically could change, with mathematical constants - such as pi - which are completely independent from the universe. Pi cannot change.


    Wrong. Pi is dependent on the curvature of space. In a largely flat space it is what we measure it to be. In a rather curved space you will find it smaller or bigger depending on the type of curvature. In the early universe it would have been much smaller so there was a time when it was 3.
  • Vitus 2012-07-10 06:33
    Planar:
    Infinite Time and Space:

    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.


    You've got it wrong. The value of PI has nothing to do with time or space, it is a mathematical constant. If you want to change the value of PI, you'll have to change the value of some integers, because of PI is defined by a number of formulas that depend only on natural numbers, for example:

    PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...

    see http://en.wikipedia.org/wiki/Pi for more formulas of the same kind.


    Nope, Pi is the ratio of circumference and diameter of a circle and that can change. The numeric methods to calculate it you mention are only valid in an Euclidean space. So yes there is conceivably a time and place where it was 3.0.
  • Peter 2012-07-10 06:43
    PiisAWheeL:
    Tristram:
    Ooh, I know how to fix this code. Works as advertised:

    // Convert to negative number

    varInt := StrToInt('-1');
    That fails on an input below 0.
    No, works perfectly. The comment says "Convert to negative number", not "Convert to opposite sign".
  • lanmind 2012-07-10 08:35
    TGV:
    you either take the Bible literally, or you don't.


    Wrong. Try again.
  • ¯\(°_o)/¯ I DUNNO LOL 2012-07-10 09:16
    function filexists($file) {
    $retval=0;
    if(file_exists($file)) $retval=1;
    return $retval;
    }

    This proves that you can write PHP in any language.
  • Hmmmm 2012-07-10 09:22
    Vitus:
    Nope, Pi is the ratio of circumference and diameter of a circle and that can change. The numeric methods to calculate it you mention are only valid in an Euclidean space. So yes there is conceivably a time and place where it was 3.0.


    Actually Pi is the ratio of the circumference and diameter of an idealised circle in flat (Euclidean) space. The value of Pi doesn't change in curved space, it is the formula C = Pi * d that changes according to the measure of the curvature of the space.
  • Infinite Time and Space 2012-07-10 09:23
    lanmind:
    TGV:
    you either take the Bible literally, or you don't.


    Wrong. Try again.


    Could be right, could be wrong. Depends if it is an AND or OR condition. If it is an AND condition, then you either take the entire bible literally, or if you take part literally and port not, then you do NOT take the bible literally. If it is on OR condition, then if you take any part of the bible literally, then you take the bible literally.

    XOR means you worship Satan, but not literally.
  • prophet's apprentice 2012-07-10 09:57
    Methuzzella:
    The very beginning of the bible is a case in point: "On the first day God created day and night"
    Well I'll be damned. Surely the day must already have existed if this was the first day?


    That's how people remember it. But acutally, whoever wrote that part of Genesis did pay some attention to detail. There God creates light, then separates light from darkness, thus causing the first day.
  • Sayer 2012-07-10 10:07
    TGV:
    Sayer:
    Or we can assume that the dude writing the passage was a scribe and not a fucking engineer - therefore making any inaccuracies in reporting the measurement hardly surprising or noteworthy.

    Someone's getting upset and using ugly words that have been forbidden by his god, or rather, the people that claim to be the representatives of his deity of preference.

    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.


    And someone's making all kinds of assumptions just because my stance against stupid and dishonest arguing has me appearing to support a viewpoint I often find idiotic.

    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.


    This is bullshit. (gosh, I hope I didn't hurt your ears) There are all kinds of reasons not to take the Bible literally, but the rounding errors or poor mathematical understanding of the guy writing it down is a pretty flimsy one. The book is full of contradictions and all kinds of other nonsense like rules on which fabrics to never wear together. Try fucking harder.
  • PedanticCurmudgeon 2012-07-10 10:13
    Herohtar:
    I was expecting one of the first comments to be a "GRAVEYARD OF BAD COMMENTS" marker. I am greatly disappointed.
    Are you new here? Every WTF posted has a graveyard of bad comments.
  • Persto 2012-07-10 10:28
    Ninkasi:
    Oh, yay, this argument again. Okay, let's run with this.

    So you're saying that 1 Kings 7 is an engineering document, and as such only needs to be accurate to within the engineering tolerances of Solomon's temple. Hey, I'll buy that. The whole chapter is discussing the dimensions of the building in detail. I guess that means the temple, then, was built to a tolerance of 1.4 cubits, or about one meter.

    Meanwhile, contemporary construction by the Egyptians was built to tolerances lower than a couple millimeters (the thickness of a sheet of papyrus, anyway). Perhaps that's why the Pyramids of Giza are still standing and Solomon's Temple, well, isn't.

    As an engineer myself, maybe I should be praying to Ra and Anubis, instead.


    That should work out fine as a Cristian, since Cristianity and of Eqyptology. and Jesus the reborn Horus or Ra.
  • PZ 2012-07-10 10:31
    I just remember being taught (and this was probably a maths class rather than a computer class) that 22/7 was a 'good enough' estimation of PI for rough calculations.

    I would guess this is where the funny code came from - somebody from a maths background (or who remembered it from a maths class), and not even realising there's another way in most computer languages these days.

  • Herr Otto Flick 2012-07-10 10:40
    Nagesh:
    Also

    Nagesh:
    null:
    public static int getNegativeOfNumber ( int num )
    {
    return num > 0 ? num * -1 : num;
    }

    U ain't remembering to put in semi-colons.


    You're all wrong:

    int negate(int num) { return 1 + ~ num; }
  • dargor17 2012-07-10 10:41
    Vitus:
    Planar:
    Infinite Time and Space:

    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.


    You've got it wrong. The value of PI has nothing to do with time or space, it is a mathematical constant. If you want to change the value of PI, you'll have to change the value of some integers, because of PI is defined by a number of formulas that depend only on natural numbers, for example:

    PI = 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ...

    see http://en.wikipedia.org/wiki/Pi for more formulas of the same kind.


    Nope, Pi is the ratio of circumference and diameter of a circle and that can change. The numeric methods to calculate it you mention are only valid in an Euclidean space. So yes there is conceivably a time and place where it was 3.0.


    Obvious troll is obvious. 1/10
  • PiisAWheeL 2012-07-10 10:43
    Infinite Time and Space:
    lanmind:
    TGV:
    you either take the Bible literally, or you don't.


    Wrong. Try again.


    Could be right, could be wrong. Depends if it is an AND or OR condition. If it is an AND condition, then you either take the entire bible literally, or if you take part literally and port not, then you do NOT take the bible literally. If it is on OR condition, then if you take any part of the bible literally, then you take the bible literally.

    XOR means you worship Satan, but not literally.
    +1
  • Tud 2012-07-10 11:07
    Vitus:
    Nope, Pi is the ratio of circumference and diameter of a circle and that can change. The numeric methods to calculate it you mention are only valid in an Euclidean space. So yes there is conceivably a time and place where it was 3.0.


    Vitus:
    Wrong. Pi is dependent on the curvature of space. In a largely flat space it is what we measure it to be. In a rather curved space you will find it smaller or bigger depending on the type of curvature. In the early universe it would have been much smaller so there was a time when it was 3.



    const real MATHEMATICAL_CONSTANT_1 := 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ... = 3.1415926535897932384...
    const real GEOMETRICAL_CONSTANT_1 := euclidean_geometry.NewCircle().circumference / euclidean_geometry.NewCircle().radius = 3.1415926535897932384...
    const real PHYSICAL_CONSTANT_1 := current_universe.drawCircle().circumference / current_universe.drawCircle().radius = 3.1415926535897932384...
    if (current_universe.getGeometry == euclidean_geometry)
    {
    assert MATHEMATICAL_CONSTANT_1 == GEOMETRICAL_CONSTANT_1 == PHYSICAL_CONSTANT_1
    }

    And since they're the same, we just call that value "Pi".
  • Slugs 2012-07-10 13:15
    N is force, which the measure of weight. g is a measure of mass. 1 kg weighs ~ 9.81 N. You apparently failed physics.
  • Zany 2012-07-10 13:37
    The boolean_table needs to support plugins, so I can extend it with "HappyHour" and "OnASunnyDay"
  • geekforgod 2012-07-10 13:46
    I just wanted to show another possibility for the Biblical value of pi.

    In 1 Kings 7:23 the molten sea is said to be 10 cubits from one brim to the other and 30 cubits in circumference.

    If you notice in verse 26, however this object is a hand breadth thick. It is possible the 30 cubits circumference is of the inner circle instead of the outer and the 10 cubits is from outer rim to outer rim.

    According to google a cubit is 18 inches.

    According to wikipedia a handbreadth is 4 inches.

    So if we substitute

    2 * 3.14 * ((10 * 18) - 8)/2 = 30(18)
    2 * 3.14 * 86 = 540
    540.08 = 540

    That value is not exact, but it sure looks close enough for me.
  • Spewin Coffee 2012-07-10 13:51
    Fil was such a great guy. Lots of people denied his existence and even spelled his name wrong on many occasions in mockery ("file", we're looking at you), but those who loved him write functions in his honor and encapsulate his memories within the integerized booleans of unnecessarily verbose programs. After all, love makes the hearts of programmers do crazy things.

    Fil, we'll miss you. Okay, now who wants some of this SHEEIT cake and PI?
  • DaveK 2012-07-10 14:22
    Not really convinced that System.Runtime.InteropServices.SEHException (which is what you'd get from a c0000005 access violation) could plausibly get mangled in that way.

  • Eldon 2012-07-10 15:32
    justsomedude:
    pjt33:

    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).


    N is a measure of force, the question was about weight. If you had been in a physics test you would have got that one wrong.


    Weight is a force, you are probably thinking about mass
  • shadowman 2012-07-10 16:30
    As someone who has never heard anything about pi and the bible before, I googled and found an interesting take on that. This link indicates that pi actually was being approximated to 3.14, when you considered the units involved.

    http://www.purplemath.com/modules/bibleval.htm

  • Mick 2012-07-10 20:36
    Modern believer in scientology:
    Methuzella wrote:
    "And I increasingly get the impression that the only people in the world who seem to think the Old Testament is anything even remotely literal are the people who want to argue that Science is right and the bible is wrong and never the twain shall meet."

    Well, just exclude christian fundamentalists and all the americans who in surveys declare that they think that everything described in the bible is true, that evolution is false, and you got it...
    Sacred books of revelation and science cannot meet because revelations are about revealed truths that must be accepted without thinking, while science is about facts and critical thinking. A revelation is written in stone, while science is constantly evolving as theories must improve to reflect correctly the facts of the physical world.
    But I am glad to know that the bible is not to be taken literally, I guess this means that sins are metaphoric expressions of moral advices, there's no hell and even the concept of soul might be a simple beautification of the idea of human nature.
    So good to know that the ten commandments are just metaphoric ideas, so I cn actually understand them as I see fit, which after all what all military chaplains have been doing when it comes to the "thou shalt not kill" thingy, since blessing men who are going to kill other men doesn't seem quite a christian idea... But luckily we are XXI century people, and we don't hold irrational beliefs and superstitious ideas.

    captcha: ideo, I create anything with my imagination and make it come true
    The Old Testament != the entire Bible.
    Not a literal book != No lessons to be taken from

    Spot on in your example on the 10 commandments - how do you think religions justify the violence in their history?

    It is intereating that you take a statement about the bible not being a literal description of fact and interpret that to mean that any concept expressed within must be a metaphor.

    Finally, I think your rant goes a good way to emphasising the OP's point. It seems many Christians (and people of other faith's) accept that Science can coexist with their beliefs, while people on the pro-Science (or rather anti-religion) page seem to take it personally when anyone suggests that they can coexist.
    If religion is a whole load of crap (which it may well be) why do you care enough to get upset about it? I can understand religious zealots getting upset when people suggest their religion is wrong but I can't understand why the non-religious people care that there are those in the world who choose to follow a religion. And yet, like the OP I think I commonly see (as above) that scientists irrationally get upset at the thought that someone still believes in religion (something that in no way affects them or the validity of scientific proof)...

    It's weird. You'd expect the religious fanatic to be the agressor (because their beliefs are challenged/threatened by science), and the scientis to be dismissive (because it's just some loonies believing odd things). Yet somehow it often appears the opposite. Strange indeed.
  • laziness_exists 2012-07-10 21:25
    Typing an underscore can be a pain. I personally love this wrapper method.
  • Steve The Cynic 2012-07-11 03:14
    laziness_exists:
    Typing an underscore can be a pain. I personally love this wrapper method.

    Depends on your keyboard, I guess. On my keyboard, 8 is a shifted underscore. The top row of the main part is ²&é"'(-è_çà)=.
  • Decius 2012-07-11 03:49
    Because it's the standard method of rounding in experimental science? If you divide 25 by 2.0, you get 12, if you divide 23 by 2.0, you also get 12. If you average 12 and 12 you get 12. If you divide the average of 23 and 25 by 2.0, you get 12. See the consistency?

    Now try rounding up- the average of 25/2.0 and 23/2.0 becomes 13 (remember significant figures), while the average of 25 and 23, divided by 2.0, is 12.
  • Peteris 2012-07-11 05:01
    You don't use floats in financial applications (or you should be hanged, quartered and then fired afterwards).
    When rounding 123.50 to whole number, or 123.005 to whole cent, there are specific rules (in law) specifying when to round up and when to round down. Adding 0.5000001 would, naturally, break everything.
  • kcim 2012-07-11 07:50
    It seems many Sientists accept that Religion can coexist with their views of the world, while people on the pro-Religion (or rather anti-science) page seem to take it personally when anyone suggests that they can coexist.
    If science is a whole load of crap why do you care enough to get upset about it? I can understand scientific zealots getting upset when people suggest their science is wrong but I can't understand why the non-science people care that there are those in the world who choose to follow science. And yet, I think I commonly see that religous people irrationally get upset at the thought that someone don't believe in religion (something that in no way affects them or the validity of their faith)...

    It's weird. You'd expect the scientists to be the agressor (because their view of the world is challenged/threatened by religion), and the religious people to be dismissive (because it's just some loonies believing odd things). Yet somehow it often appears the opposite. Strange indeed.
  • Tynam 2012-07-11 09:40
    Mick, while I try to avoid the tendancy to rant... it's not that weird that scientists defend themselves aggressively. It's cause and effect.

    Why do I care that there are people in the world who choose to follow a religion? Becuase some of those people have an almost total lock on important public policy decisions, and they keep using it to make *stupid* decisions as a result.
    I have no choice but to care.

    After fifty years of science there are still people denying that global warming exists, and recently - for the first time - churches are major motivators in that. After a century and a half of science people (and I mostly mean 'USA-based evangelicals') are still denying evolution, and churches are the *only* motivators in that.

    We scientists are becoming aggressive because we're frustrated by being under non-stop church-driven long-range attack. There's no point being surprised that people who keep being shelled react badly to the sound of gunfire. (Unhelpful, sure. But very human.)

    Dawkins is an overly-aggressive idiot who harms his cause every other time he opens his mouth. But it's easy to see how he got that way.

    (Captcha: erat. *He was* a much calmer man, back when he could study biology biology without incurring a five-minute-hate campaign from half the US.)
  • Captcha:laoreet 2012-07-11 10:28
    Tynam:
    Why do I care that there are people in the world who choose to follow a religion? Becuase some of those people have an almost total lock on important public policy decisions, and they keep using it to make *stupid* decisions as a result.
    I have no choice but to care.

    After fifty years of science there are still people denying that global warming exists, and recently - for the first time - churches are major motivators in that. After a century and a half of science people (and I mostly mean 'USA-based evangelicals') are still denying evolution, and churches are the *only* motivators in that.

    There's an xkcd for that.

    (154)
  • Neil 2012-07-11 11:28
    Ken B.:
    PZ:
    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.
    Given that it's only accurate to 2 decimal places, I would think hard-coding "3.14" would be easier.

    Either that, or "355./113". It's only 1 character longer than "22.0f/3" and it's accurate to 6 decimal places.
    Assuming that PZ wanted an IEEE float, rather than a double, 355.f/113 would have exactly equalled π, within the limits of available precision.
  • beowulf 2012-07-11 11:59
    PI cant still be calculated in some languages like VBA
    But you can use the math formular 4 * ATN(1) (arc tangent)
  • qbolec 2012-07-11 13:28
    Perhaps you are just trolling, but the idea that using "round to odd" is always better than "round up" is a bit wrong and contains some hidden assumptions about data distribution.

    For I agree that if all your data are exactly half way between two integers, then you'll get better total sum if you decide to round at least some of them down instead of rounding up. And this is what happens if some of the numbers have odd and some have even integer parts. But this just seems to me as a "pseudo-random algorithm", which fails if all values have same integer part.

    Furthermore, if your data points are of form x+0.50001 or x+0.499999, or anything else which isn't always a multiple of 0.5 then there is no difference between the two methods. And if for some reason you know all your data is a multiple of 0.5, then why don't you just multiply everything by 2, and use integers?

    OK, I lost my point, but it was something like "you know, if you need a way to deal with those pesky x+0.5 values in your data set, then just count their number (n) and add n/2 to your result and don't rely on pseudorandomness".
  • Buho 2012-07-11 14:00
    "But pi is a constant that will never be 3."

    Pi is a constant that will never be ANY written representation. Rounding must occur somewhere. The place where where pi is calculated in the Bible wasn't concerned with precision.
  • Jeremy 2012-07-11 22:06
    KattMan:
    The Christian bible states that PI is 3. No floats needed back in those days I guess.


    Actually Noah needed a good number of them.
  • Jeremy 2012-07-11 22:14
    ShatteredArm:
    {"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."


    One possible problem is that the value of "Maybe" is computed at compile time, so the value that Maybe represents will be the same across all runs of the program (at least until the next time it is recompiled).

    Dunno if that's a bug or a feature.
  • David Conrad 2012-07-12 00:12
    Anonymous Genius:
    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.


    In financial applications, if you are caught using floating point for monetary values you will be lucky if they just fire you and don't take you out back and shoot you.
  • David Conrad 2012-07-12 00:27
    TGV:
    you either take the Bible literally, or you don't. There is no FileNotFound option.


    There is ALWAYS a FileNotFound option in addition to all other options, even when it doesn't logically make any sense. That is the WHOLE POINT of a FileNotFound option!

    Heretic.
  • David Conrad 2012-07-12 00:39
    Whosdr:
    Any real computer or maths buff should know Pi is roughly 3.14159265358979323846264338327950288419716939937510582097494492307.
    Come on, is it really that hard to remember?


    You missed a spot. Near the end (of what you gave) it is ...494459..., not ...49449....
  • lokedhs 2012-07-12 01:23
    History Teacher:
    Anonymous Genius:
    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.


    Not always. There are plenty of financial calculations where floats are fine. Generally, they are dealing with things like estimated future profits, volatilities, etc.

    Not all of finance is about keeping track of money in accounts.
  • Whosdr 2012-07-12 06:20
    Typo. Not used to using the numpad but it was the quickest way. Why don't you give it a try?

    Fixed:
    3.1415926535897932384626433832795028841971693993751058209749445923078
  • mschutte369 2012-07-12 12:52
    [qoute]"There are many ways to convert a number to a negative," writes Rafael L, "this, I suppose, is one of them."

    // Convert to negative number
    varInt := StrToInt('-' + IntToStr(varInt));
    [/quote]

    This isn't nearly as bad as I once did in one of my first programs in my first position as a programmer. Minoring in Math, I stupidly coded this to make the number negative.

    This may make more since to those of you familiar with RPGIV fix format code.

    C 2 MULT MYNBR HLDVAL
    C MYNBR SUB HLDVAL MYNBR

    basically it's the same as coding this.

    MyNbr = MyNbr - (MyNbr * 2)

    My boss came to me and said, why not just multiple by negative one. I just slapped myself in the head and changed the code.

    At my new place of employment. RPGIII code is still rampant. I've seen this code to make the value negative.

    C Z-SUB MYNBR MYNBR

    which is the same as saying

    MYNBR = 0 - MYNBR
  • PedanticCurmudgeon 2012-07-12 13:48
    kcim:
    It's weird. You'd expect the scientists to be the agressor (because their view of the world is challenged/threatened by religion), and the religious people to be dismissive (because it's just some loonies believing odd things). Yet somehow it often appears the opposite. Strange indeed.
    It's not weird. Scientists simply have a different set of enemies. If you want to see rabid opposition from a scientist, all you have to do is suggest to them that astrology or homeopathy really works.
  • Joe 2012-07-12 15:48
    Heinz:

    You can get this code to fail:

    /**
    * Tests if {@link XXXX} class extends {@link Object} class.
    */
    @Test
    public void testInheritance() {
    Assert.assertTrue("Class does not extends Object class.",
    instance instanceof Object);
    }

    Simply pass in "null".

    Pass into what? It's a class method with no arguments that tests itself.

    Can you evoke methods on a null reference without taking a NullPointerException due to the reference being null? (I'm admittedly not a Java expert.)

    Can you give a snippet of code that would invoke this method on a null reference?
  • radarbob 2012-07-12 15:59
    Nagesh:
    PZ:
    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!


    There's no comma-pause when the REAL Nagesh mispromunchinates.
  • Joe 2012-07-12 16:11
    Jamal:

    Remember: it is always praferrable to put the inside of the function in one line to spend less space and make the client happy:

    public static int getNegativeOfNumber ( int num )
    {
    return -1*Math.abs(num);
    }


    And then there's the inscrutable C/C++ branchless approach:

    static inline int get_negative_of_number(int num) { return (num & (num >> 31)) - (num & ~(num >> 31)); }
  • Joe 2012-07-12 16:25
    Jeremy:
    ShatteredArm:
    {"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."


    One possible problem is that the value of "Maybe" is computed at compile time, so the value that Maybe represents will be the same across all runs of the program (at least until the next time it is recompiled).

    Dunno if that's a bug or a feature.


    I'd say the answer is a definite maybe.
  • Joe 2012-07-12 16:30
    Joe:

    And then there's the inscrutable C/C++ branchless approach:

    static inline int get_negative_of_number(int num)
    {
    return (num & (num >> 31)) - (num & ~(num >> 31));
    }

    Assuming, of course, the spec was to return a negative number given any 'int'. And for extra bonus points, there's the inscrutable C/C++ float version:
    static inline float get_negative_of_float(float f) 
    
    {
    union { float f; int i; } x;
    x.f = f;
    x.i |= 0x80000000U;
    return x.f;
    }
  • RonPaul 2012-07-14 00:14
    The rounding routine isn't horrible as the default Math.Round rounds to even on midpoints which will bite you sometimes. However, I believe a simple overload will do everything that routine does: Math.Round(decimal, intDecimalPlaces, MidpointRounding.AwayFromZero)
  • RonPaul 2012-07-14 00:17
    Double as well.

    Math.Round(double, intDecimalPlaces, MidpointRounding.AwayFromZero)
  • David 2012-07-14 07:18
    Jay:
    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.


    It shows that they didn't understand that didn't understand that pi exists at all; if you're working to one significant digit, there's absolutely no reason to give the diameter and circumference of a circular object.
  • Luiz Felipe 2012-07-14 15:33
    Heinz:
    You can get this code to fail:



    /**
    * Tests if {@link XXXX} class extends {@link Object} class.
    */
    @Test
    public void testInheritance() {
    Assert.assertTrue("Class does not extends Object class.",
    instance instanceof Object);
    }



    Simply pass in "null".


    Null is void, and void is not an object. where is your object's gawd now?
  • Luiz Felipe 2012-07-14 16:04
    Tud:
    Vitus:
    Nope, Pi is the ratio of circumference and diameter of a circle and that can change. The numeric methods to calculate it you mention are only valid in an Euclidean space. So yes there is conceivably a time and place where it was 3.0.


    Vitus:
    Wrong. Pi is dependent on the curvature of space. In a largely flat space it is what we measure it to be. In a rather curved space you will find it smaller or bigger depending on the type of curvature. In the early universe it would have been much smaller so there was a time when it was 3.



    const real MATHEMATICAL_CONSTANT_1 := 4/1 - 4/3 + 4/5 - 4/7 + 4/9 - 4/11 + ... = 3.1415926535897932384...
    const real GEOMETRICAL_CONSTANT_1 := euclidean_geometry.NewCircle().circumference / euclidean_geometry.NewCircle().radius = 3.1415926535897932384...
    const real PHYSICAL_CONSTANT_1 := current_universe.drawCircle().circumference / current_universe.drawCircle().radius = 3.1415926535897932384...
    if (current_universe.getGeometry == euclidean_geometry)
    {
    assert MATHEMATICAL_CONSTANT_1 == GEOMETRICAL_CONSTANT_1 == PHYSICAL_CONSTANT_1
    }

    And since they're the same, we just call that value "Pi".


    Assetion fail: current_universe.getGeometry returned space_time_continuum class.
  • Luiz Felipe 2012-07-14 16:18
    Mick:
    Modern believer in scientology:
    Methuzella wrote:
    "And I increasingly get the impression that the only people in the world who seem to think the Old Testament is anything even remotely literal are the people who want to argue that Science is right and the bible is wrong and never the twain shall meet."

    Well, just exclude christian fundamentalists and all the americans who in surveys declare that they think that everything described in the bible is true, that evolution is false, and you got it...
    Sacred books of revelation and science cannot meet because revelations are about revealed truths that must be accepted without thinking, while science is about facts and critical thinking. A revelation is written in stone, while science is constantly evolving as theories must improve to reflect correctly the facts of the physical world.
    But I am glad to know that the bible is not to be taken literally, I guess this means that sins are metaphoric expressions of moral advices, there's no hell and even the concept of soul might be a simple beautification of the idea of human nature.
    So good to know that the ten commandments are just metaphoric ideas, so I cn actually understand them as I see fit, which after all what all military chaplains have been doing when it comes to the "thou shalt not kill" thingy, since blessing men who are going to kill other men doesn't seem quite a christian idea... But luckily we are XXI century people, and we don't hold irrational beliefs and superstitious ideas.

    captcha: ideo, I create anything with my imagination and make it come true
    The Old Testament != the entire Bible.
    Not a literal book != No lessons to be taken from

    Spot on in your example on the 10 commandments - how do you think religions justify the violence in their history?

    It is intereating that you take a statement about the bible not being a literal description of fact and interpret that to mean that any concept expressed within must be a metaphor.

    Finally, I think your rant goes a good way to emphasising the OP's point. It seems many Christians (and people of other faith's) accept that Science can coexist with their beliefs, while people on the pro-Science (or rather anti-religion) page seem to take it personally when anyone suggests that they can coexist.
    If religion is a whole load of crap (which it may well be) why do you care enough to get upset about it? I can understand religious zealots getting upset when people suggest their religion is wrong but I can't understand why the non-religious people care that there are those in the world who choose to follow a religion. And yet, like the OP I think I commonly see (as above) that scientists irrationally get upset at the thought that someone still believes in religion (something that in no way affects them or the validity of scientific proof)...

    It's weird. You'd expect the religious fanatic to be the agressor (because their beliefs are challenged/threatened by science), and the scientis to be dismissive (because it's just some loonies believing odd things). Yet somehow it often appears the opposite. Strange indeed.


    This is because religious people spread a lot of lies or wrong knowledge that don't take humanity forward. Misconceptions and wrong knowledge must be eradicated.
    I see quite opposite, a lot of scientists coexists his religious faith with science, but majority dismiss it. Is the religious people that are upset because they can't accept that someone has an divergent opinion.
    But fanatics exists on both sides, i see much more fanatics on religion than on science.
    Scientists denials much of religion as a myth or fairy tales, they aren't upset, they are just denying, it is their personal opinion, not science opinion. You can pretty much believe or not believe in anything. Some religious people that are upset because of this, because they can't grasp that someone don’t believe what they believe. Yes, they are wrong in thinking that way.
  • Luiz Felipe 2012-07-14 16:26
    PedanticCurmudgeon:
    kcim:
    It's weird. You'd expect the scientists to be the agressor (because their view of the world is challenged/threatened by religion), and the religious people to be dismissive (because it's just some loonies believing odd things). Yet somehow it often appears the opposite. Strange indeed.
    It's not weird. Scientists simply have a different set of enemies. If you want to see rabid opposition from a scientist, all you have to do is suggest to them that astrology or homeopathy really works.

    No, if you only suggest to them that it works, they will not be upset. You must put the burden of proving that homeopathy don`t works on them. Inversion of proof, it is the people that believe in astrology or whatever that must prove that astrology works, not some other people, this upset every person that has a little of intelligence, logic and rationality. If you cant prove what you are saying, then you are lier and charlatan.
  • KMag 2012-07-15 10:57
    half-to-even is the most commonly used "unbiased" rounding conventions. I hope it's also the rounding method you learned in your Junior High science classes.

    I'm not sure what the split is in elementary schools teaching half-towards-+Infinity vs. half-away-from-zero. In any case, you'll find that even within the U.S., different schools teach different rules for rounding negative numbers.

    This also happens to be the default rounding mode for IEEE 754 floating point calculations. (It's also the recommended default for IEEE 754-2008 decimal floating point calculations.)

    If you don't know enough to know what kind of rounding you want, scientific rounding is probably the safest default. If you wanted half-away-from-zero, you'll probably figure it out fast enough. However, if you're doing scientific calculations (or porting scientific code from another language) and you use a biased rounding convention, the bugs will be much more subtle. Given a choice between surprising ignorant people but doing what's likely the safe thing (unbiased rounding, bankers' rounding, correct for scientific/engineering calculations) vs. doing something that quickly surprises ignorant programmers and prompts them to educate themselves.... well, I think the IEEE 754 committee made a good choice.

    Rounding half-away-from-zero when an unbiased rounding is called for is more likely to cause a fatality (engineering code) or significant money loss (econometrics code) than vice-versa.

    The Real WTF is criticizing rounding conventions without sitting down to understand them first.
  • KMag 2012-07-15 10:59
    Kaniu:
    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


    half-to-even is the most commonly used "unbiased" rounding conventions. I hope it's also the rounding method you learned in your Junior High science classes.

    I'm not sure what the split is in elementary schools teaching half-towards-+Infinity vs. half-away-from-zero. In any case, you'll find that even within the U.S., different schools teach different rules for rounding negative numbers.

    This also happens to be the default rounding mode for IEEE 754 floating point calculations. (It's also the recommended default for IEEE 754-2008 decimal floating point calculations.)

    If you don't know enough to know what kind of rounding you want, scientific rounding is probably the safest default. If you wanted half-away-from-zero, you'll probably figure it out fast enough. However, if you're doing scientific calculations (or porting scientific code from another language) and you use a biased rounding convention, the bugs will be much more subtle. Given a choice between surprising ignorant people but doing what's likely the safe thing (unbiased rounding, bankers' rounding, correct for scientific/engineering calculations) vs. doing something that quickly surprises ignorant programmers and prompts them to educate themselves.... well, I think the IEEE 754 committee made a good choice.

    Rounding half-away-from-zero when an unbiased rounding is called for is more likely to cause a fatality (engineering code) or significant money loss (econometrics code) than vice-versa.

    The Real WTF is criticizing rounding conventions without sitting down to understand them first.
  • AN AMAZING CODER 2012-07-16 01:22
    Nagesh:
    TGV:
    Sayer: you either take the Bible literally, or you don't. There is no FileNotFound option.
    I don't. You got a problem with that?

    But even so, the literal meaning of "thirty cubits" is not "30.0 cubits exactly". None of the extant manuscript include the word "exactly" (or rather, any words in the original language, probably biblical Hebrew, that would support such a translation). There is no reason to exist any such manuscript ever existed.


    All of you are getting so upset, you're forgetting that a cubit was not exact to begin with.

    It's like saying "a shot" as a liquid measurement today, and getting angry over an interpretation of how much wine Jesus actually made from water.
  • PedanticCurmudgeon 2012-07-16 08:21
    Luiz Felipe:
    No, if you only suggest to them that it works, they will not be upset. You must put the burden of proving that homeopathy don`t works on them. Inversion of proof, it is the people that believe in astrology or whatever that must prove that astrology works, not some other people, this upset every person that has a little of intelligence, logic and rationality. If you cant prove what you are saying, then you are lier and charlatan.
    So let's see the proof of your last statement.
  • TheJim 2012-07-17 06:13
    Um, no.

    Weight is a type of force, measured in newtons (or pounds, etc.). Mass is a measure of amount of matter, NOT A force, and is measured in kilograms (or whatever the Imperial unit of mass is - I used to know this). Since weight is a force, units of force are the only correct way to answer that question as it's worded.
  • TheJim 2012-07-17 06:28
    This makes no sense. We're talking about a ParseInt function, not eval(), so syntax of the host language could never apply. Even in C++ one would expect itoa() or equivalents to fail on a double negative.

    Captcha: genitus (the ringing in your ears from the Big Bang)
  • TheJim 2012-07-17 06:51
    The fact that Pi began life as the ratio between a circle's circumference and its diameter has no bearing on the fact that it has since become a fixed mathematical constant with implications far beyond its original meaning. To name one example: complex numbers/mathematics/analysis relies on Euler's relation, which incorporates a fixed constant known as Pi. Another example: solution of differential equations often requires e.g. the Fourier transform, which also relies on Pi and complex numbers.

    The ways in which Pi is used in these two areas have nothing to do with physical geometry, and if you try to use a different value for Pi, the maths BREAKS, period.

    This gets more confusing when one considers quantum mechanics, i.e. a physical theory where geometry is relevant. While one might try to solve QM in a non-Euclidian spatial geometry where the physical value of Pi is different, you still can't alter the mathematical constant Pi on which the complex mathematics describing the evolution of the wavefunction rests; if you do, the maths will break and your results will be garbage.

    Summary: using "Pi" to name the ratio of circumference to diameter of a circle in non-Euclidian spatial geometries is incorrect unless prefixed (e.g. "physical", "local") to make clear that it's being used as a shorthand for a curvature metric. Used unqualified, it refers to a fixed mathematical constant that will never change because its meaning has, for centuries, transcended physical geometry.
  • method1 2012-08-04 14:05
    C-Derb:
    Back in 1950 you could fool people into thinking $.57 9/10 is 3 cents cheaper than $.60

    I think US gas in 1950 was perhaps 18 cents per gallon, rather than 60 cents.
  • negro 2012-08-08 09:05
    http://msdn.microsoft.com/en-us/library/ms131275.aspx

    What exactly is this function lacking?
  • Sigh 2012-11-19 08:02
    The real WTF is in the comments.

    Do people really think that writing -1*x is better than -x? Are there popular languages where that doesn't work? Are there popular languages where that doesn't compile to a simple integer negation operation, which will be as fast as or faster than multiplication (or subtraction as in 0 - x) in all cases? Of course, if you want to force the sign to negative, -abs(x) should be just great.