• PZ (unregistered)

    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 (unregistered) in reply to PZ
    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 (unregistered)

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

  • (cs) in reply to Nagesh
    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 (unregistered)
    public static int getNegativeOfNumber ( int num ) 
    {
       int absolueValue=Math.abs(num) ;
       int negativeInt=-1*absolueValue ;
       return negativeInt;
    }
    
  • Jerry (unregistered)
    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 (unregistered)

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

  • C-Derb (unregistered)
    // 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 (unregistered)

    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 (unregistered)
    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. (unregistered) in reply to PZ
    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 (unregistered)
    {"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 (unregistered) in reply to Chronomium

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

  • (cs) in reply to C-Derb
    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 (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to Paul
    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 (unregistered) in reply to Shaftway

    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 (unregistered) in reply to Nagesh
    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 (unregistered)

    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 (unregistered)

    The filexists function can be explained by print statement debugging.

  • Fred (unregistered)
    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 (unregistered) in reply to KattMan
    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 (unregistered) in reply to Anonymous Genius
    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.
  • (cs) in reply to History Teacher
    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 (unregistered) in reply to Anonymous Genius
    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 (unregistered) in reply to KattMan
    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 (unregistered) in reply to KattMan
    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

  • (cs) in reply to KattMan
    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.
  • (cs) in reply to Pastor Eyes
    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.
  • (cs)

    {"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 (unregistered) in reply to Anonymous Genius
    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)

  • (cs) in reply to operagost
    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.
  • (cs) in reply to operagost
    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.

  • (cs)

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

  • Infinite Time and Space (unregistered) in reply to operagost
    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.

  • (cs) in reply to Some Damn Yank
    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.
  • (cs) in reply to Pavel
    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 (unregistered)

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

  • Canada Eh? (unregistered) in reply to operagost
    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 (unregistered)

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

    // Convert to negative number

    varInt := StrToInt('-1');

  • Born Texas Proud (unregistered) in reply to Infinite Time and Space
    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 (unregistered)

    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 (unregistered)

    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 (unregistered) in reply to Sagan

    x=atan(1)*4

    is perfect!

  • Jinren (unregistered) in reply to KattMan
    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 (unregistered) in reply to KattMan
    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 (unregistered)

    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.

  • (cs)

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

  • (cs) in reply to Jay
    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).

Leave a comment on “The Object Test, a New PI, and More SHEEIT”

Log In or post as a guest

Replying to comment #:

« Return to Article