Char *__PI = "3,1416" ;



  • I saw this on a forum, link below.
    Here's how it goes: The original poster of the question was asking on the C++ forum how he could draw an ellipse. Ok, someones paste a code.
    Then, comes this guy called sitesrox, and says that the constant PI defined on the code pasted is wrong, and the correct constant of PI, is this one, posted by him:

     

    char *__PI = "3,1416" ;

     

    Awesome.
    A floating point constant, declared as char. With "," as decimal separator, breaking internationalization.

    You can see the thread here:

    http://www.unidev.com.br/forum/topic.asp?TOPIC_ID=29450

    It's right after the second code snippet. Or search for his name, sitesrox.



  • Is that perhaps the right way to declare floating point constants in QBASIC? I've never used it.



  • @Lews said:

    Is that perhaps the right way to declare floating point constants in QBASIC? I've never used it.


    Sure as hell not.



  • "I know all those words, but that sign doesn't make any sense"

     



  • Well I'm just happy someone set him straight.

    NEGATIVO sitesrox!!!

    A elipse vai surgir sim...

    Sinceramente eu não compreendo muito a funcionalidade deste código, mas eu sei usá-lo. E se você copiar e colar no QB45, CONCERTEZA, vai surgir mua elipse no meio da tela...

    E se você quizer pode deixá-la mais achatada, ou menos achatada, menor ou maior, e na posição escolhida!!!



  • <FONT face=Georgia color=#ff0000>I like how they're all talking in Spanish but paste a code snippet as an example with english comments.  I'd figure they'd rip the code, then at least re-comment the code in their native language. They are trying to help out a novice, no?  Geesh.  Thus, I digress. :)</FONT>

    <FONT face=Courier>'***Programming example for the SIN function***
    CLS
    CONST PI = 3.141593
    SCREEN 1: COLOR 1, 1             'Medium resolution, blue background.
    WINDOW (-3, -2)-(3, 2)           'Convert screen to Cartesian coordinates.
    INPUT "Number of petals = ", N
    CLS
    PSET (1, 0)                      'Set initial point.
    FOR Angle = 0 TO 2 * PI STEP .02
       R = 1 + SIN(N * Angle)        'Polar equation for "flower."
       X = R * COS(Angle)            'Convert polar coordinates to
       Y = R * SIN(Angle)            'Cartesian coordinates.
       LINE -(X, Y)                  'Draw line from previous point to new point.
    NEXT
    END</FONT>



  • @TomCo said:

    <font color="#ff0000" face="Georgia">I like how they're all talking in Spanish but paste a code snippet as an example with english comments.  I'd figure they'd rip the code, then at least re-comment the code in their native language. They are trying to help out a novice, no?  Geesh.  Thus, I digress. :)</font>


    Although I'm dutch, almost all my comments are plain english, since well, it seems more natural to me to comment my code in english and it's friendlier to others as well :-).  



  • @TomCo said:

    <font color="#ff0000" face="Georgia">I like how they're all talking in Spanish but paste a code snippet as an example with english comments.  I'd figure they'd rip the code, then at least re-comment the code in their native language. They are trying to help out a novice, no?  Geesh.  Thus, I digress. :)</font>

    <font face="Courier">


    Actually, they're talking Portuguese. Brazilian Portuguese, to be exact. Which is what you'd expect from a site found at a domain ending in ".br".
    </font>



  • There seems to be a misunderstanding here.  First, the language is Portuguese.  Second, "sitesrox" is not saying to declare the value as a character string, and to use a comma in place of the decimal point.  His comment is:

    <font face="Verdana, Arial, Helvetica"><font color="black" face="Verdana, Arial, Helvetica" size="2"> Se CONST PI for o numeral PI o valor esta errado, os primeiros</font></font>
    <font face="Verdana, Arial, Helvetica"><font color="black" face="Verdana, Arial, Helvetica" size="2"> 5 digitos do PI sao equivalentes a:</font>

    <font color="black" face="Verdana, Arial, Helvetica" size="2">char *__PI = "3,1416" ;</font>

    <font color="black" face="Verdana, Arial, Helvetica" size="2">//---------------------------//</font>

    </font>
    <font face="Verdana, Arial, Helvetica">

    <font color="black" face="Verdana, Arial, Helvetica" size="2">Entao pode tentar e ter certeza que u elipse naov ai surgir =(</font>

    </font>
    Which translates roughly to:

    "If CONST PI represents the numerical PI, the value is wrong.  The first 5 digits of PI are equivalent to...  You can try and be certain that your ellipse will not appear."
    In this context, he is merely stating that the value for PI presented by the other poster (3.141593) is wrong and that he should use "3.1416" instead, or his ellipse will not show up properly.

    My guess is that "sitesrox" is a student, and is used to using that value verbatim (probably provided by a teacher), and doesn't really understand what it stands for.  Furthermore, I think he just copy+pasted that line of code from one of his own examples (probably from a book, a teacher, or a web site) instead of typing the number.  This would explain why he said "the 5 digits are equivalent to", and not "Use the following code".

    And the comma?  Well, his compiler is probably localized and accepts the comma as the decimal separator, so his example sources contain commas where we would use a period.  This is fairly common in other countries.

    In any case, either number is correct -- in the context of programming -- as both of them are just rounding-off at different points the ever-lasting sequence of decimal places of the PI constant.

        -dZ.



  • Besides which, he should be using 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 anyway.



  • @Isuwen said:

    Besides which, he should be using 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679 anyway.


    I have PI stored on a 1 Gig flash card, in case I need to make REALLY accurate circles, or do periodic transformations on hadrons expressed as superstrings.

    The card is full, by the way.



  • People, in case most of you missed it, the WTF I've "found" is that he's declaring a constant floating point value as an array of char, also known as string. And this value he's declaring isn't a constant.
    Got it?



  • @Savior said:

    People, in case most of you missed it, the WTF I've "found" is that he's declaring a constant floating point value as an array of char, also known as string. And this value he's declaring isn't a constant.
    Got it?


    And I think you still missed the point of the poster, sitesrox.  He wasn't giving a code example, he was stating that the value was wrong and should be as the value he posted in the code.  The sample code he posted could have been taken out of some book or web site and is inconsequential.  For all you know it could have been from a function that prints the value or writes it to a file, and so it is perfectly OK to declare it as a string.

    But again, it doesn't matter because sitesrox was commenting on the value.  The fact that his value is another rounded-off approximation of PI, that's the WTF.

       -dZ.



  • @Savior said:

    People, in case most of you missed it, the WTF I've "found" is that he's declaring a constant floating point value as an array of char, also known as string. And this value he's declaring isn't a constant.
    Got it?


    There is nothing wrong about that. Since PI is a transcental number, a float or double constant is not precise enough to store its value. The only right way to go is a string of infinite length. Since that would require infinite memore, a compromise has to be made, so it is a string of finite length. But that string cannot be a constant, because later in the program more precision might be required, so the string has to be replaced with a longer (more precise) one.


    <font size="-2">If you think I'm serious, your sarcasm detector is broken.
    </font>



  • The real WTF is that there are still people using QuickBasic 4.5, which admittedly is light-years ahead of most of the other BASICs, but still..


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.