Test Everything



  • So I'm kicking myself today after a custom control was showing strange behavior because I saw this in a setter (C#):

    x = value * (10 ^ SomeOtherProperty)

    It was a simple change when I put it in so I didn't bother to test it before checking it in.  That will teach me.

    (For those not doing C# it doesn't use carrot for exponents, but rather bitwise XOR)



  • I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    Brainf*ck.


  • sockdevs

    @locallunatic said:

    (For those not doing C# it doesn't use carrot for exponents, but rather bitwise XOR)

    The only way to do exponents in C# is Math.Pow(a, e).

    Not a correction, just extra info for those not familiar with C# :)

     



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?


    Applesoft BASIC (brought to you by Microsoft, of course).



  • @RaceProUK said:

    @locallunatic said:

    (For those not doing C# it doesn't use carrot for exponents, but rather bitwise XOR)

    The only way to do exponents in C# is Math.Pow(a, e).

    Not a correction, just extra info for those not familiar with C# :)

     

    I'm rusty with C#, but I think you could also overload some operators. But you could and you did, you'd be a dick.

    edit: Also this:

    public class PedanticDickweedery {

      public static int pow (int x, int y) {

        if (y == 0) return 1;

        int originalValue = x;

        for (int i = 0; i < y; i++) {

          x *= originalResult;

        }

        return x;

      }

    }



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    What I love is that so many languages have stuck with this despite the fact that I am 10^4 times more likely to need exponentiation over bitwise operations. It must be part of the Language Creators' Code:

    @Language Creator's Code said:

    If a useful feature would make your language look less like poorly-formed, decades-old C, then that feature should not be included. If anyone asks why you did it that way just tell them "That's how C does it", even if it makes no rational sense why your 21st century, object-oriented, dynamic scripting language should look like something dropped out of the ass-end of BSD.



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    Python does that:

    >>a = 3
    >>10**a
    1000
    

    It even has support for complex numbers:

    >>(-10)**1.1
    (-11.973092164164026-3.89029346894877j)
    


  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    IIRC Fortran used ** as the exponentiation operator; I have heard it said that the ommision of an exponentiation operator in C (and C++) is an insult to scientific programmers, at least according to scientific programmers.

     



  • Lua is the other way around: x^y is exponentiation; XOR is bit.bxor. (The bit.* functions have a b prefix because bit.and and bit.or would be syntax errors, since and/or are keywords.)



  • Wild ass guess: Mathematica?



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?


    Well, BASICA, GWBASIC, and APL, off the top of my head. APL's my favourite because the syntax would be 10*x (in APL, 10 multiplied by x would be typed as 10×x, in case you were wondering; and yes, a key on an APL keyboard CAN produce one of up to four characters, depending on which shift keys you press with it).



  •  @Cad Delworth said:

    @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?


    Well, BASICA, GWBASIC, and APL, off the top of my head. APL's my favourite because the syntax would be 10*x (in APL, 10 multiplied by x would be typed as 10×x, in case you were wondering; and yes, a key on an APL keyboard CAN produce one of up to four characters, depending on which shift keys you press with it).
    And as mentioned above, FORTRAN, which is probably why it's also available in PL/I.

     



  • @esoterik said:

    @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    IIRC Fortran used ** as the exponentiation operator

    Used? I'm pretty sure Fortran still exists.

    Pascal uses **, as well.


  • Discourse touched me in a no-no place

    @locallunatic said:

    For those not doing C# it doesn't use carrot for exponents[...]
    Perhaps they could have used a potato or turnip instead? :D



  • Unrealscript uses ** too. Whenever I see it I insert a random curseword mentally.



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    Visual Basic, of course.

    Seriously, a lot: Ada, Algol, …, Zeno.

    @morbiuswilters said:

    What I love is that so many languages have stuck with this despite the fact that I am 14 times more likely to need exponentiation over bitwise operations.
    FTFY

     



  • @m said:

    @morbiuswilters said:

    What I love is that so many languages have stuck with this despite the fact that I am 14 times more likely to need exponentiation over bitwise operations.
    FTFY

    Wow, was going to post that it would be a bitwise (binary) or, not a decimal digit or....but for this case (and a few others) the two yield the same result.....



  • @Spectre said:

    Pascal uses **, as well.

    This convinces me even more that the guy teaching me computer stuff in college (a long time ago, and no, it wasn't a computer sciences course :)) didn't know his a$ from his elbow … He had us writing programs in Pascal, and when I (having experience almost exclusively with BASIC at that point) used a^2 in one of them, found it didn't work and asked him about it, did he tell me a**2 would work? No … In the end I went for a*a (which IIRC was not remarked upon by said teacher, incidentally) and wondered to myself if I'd have to do a loop for higher powers.

    This was one of the things that put me off Pascal for good :)



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    $ perl -E 'say 103;'
    1000

    I think is probably the most popular way to write exponentials in programming languages.



  • @Gurth said:

    did he tell me a*2 would work? No … In the end I went for aa (which IIRC was not remarked upon by said teacher, incidentally) and wondered to myself if I'd have to do a loop for higher powers.
     

    Ever get around to wondering how you'd handle it when both the base and the exponent were something other than positive integers?


  • sockdevs

    @da Doctah said:

    @Gurth said:

    did he tell me a2 would work? No … In the end I went for aa (which IIRC was not remarked upon by said teacher, incidentally) and wondered to myself if I'd have to do a loop for higher powers.
     

    Ever get around to wondering how you'd handle it when both the base and the exponent were something other than positive integers?

    Nope - it's well-defined. For example, a*-2 is the same as 1/(a2).

    Also, a0 == 1.

     



  • @morbiuswilters said:

    @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    What I love is that so many languages have stuck with this despite the fact that I am 10^4 times more likely to need exponentiation over bitwise operations

    I kinda understand C-syntax languages doing it for the sort of "backward-compatibility" (as in don't change the meaning of expressions that are valid in both languages). Stil no excuse to not include a exponential operator though, as lots of languages have them. Altough I do understand them not using ** (C uses it for pointers, and unmanaged/unsafe C# code does too)

    Especially since I think the reason they didn't include a exponential operator in C is because it would increase the size of the compiler, which is not an issue nowadays.



  • @RaceProUK said:

    @da Doctah said:

    @Gurth said:

    did he tell me a2 would work? No … In the end I went for aa (which IIRC was not remarked upon by said teacher, incidentally) and wondered to myself if I'd have to do a loop for higher powers.
     

    Ever get around to wondering how you'd handle it when both the base and the exponent were something other than positive integers?

    Nope - it's well-defined. For example, a*-2 is the same as 1/(a2).

    Also, a0 == 1.

     

     

    Not reading the tags, are we?

    If you've got this all figured out, I'm sure you wouldn't mind giving me the values of:

    • 00
    • 0-1
    • -10.5

     


  • sockdevs

    00 could be 1, or it could be indeterminate - both are accepted

    0-1 is undefined, as it becomes division by zero

    -10.5  = i (complex numbers)

     



  • @Rhywden said:

    I'm not sure, but is there actually a language which does not require using a function to calculate something like 10x?

    IIRC GlovePIE not only uses ^ for exponation, but ^^ for tetration.



  • @RaceProUK said:

    00 could be 1, or it could be indeterminate - both are accepted

    Not in my neighborhood they're not.  00 is one of the classic "indeterminate forms", along with 0/0 and ∞ - ∞.  If you've got a mathematical expression and it can be manipulated into any of these, it's indeterminate, case closed, end of story, take the tents down and clean the cages.  If you give your answer as 1, it's not just incomplete, it's wrong-wrong-wrongity-wrong.

    @RaceProUK said:

    0-1 is undefined, as it becomes division by zero

    -10.5  = i (complex numbers)

     

    And let's see you derive any of those as the result of a loop as was suggested when the thread went in this direction.

     


  • sockdevs

    @da Doctah said:

    @RaceProUK said:

    00 could be 1, or it could be indeterminate - both are accepted

    Not in my neighborhood they're not.  00 is one of the classic "indeterminate forms", along with 0/0 and ∞ - ∞.  If you've got a mathematical expression and it can be manipulated into any of these, it's indeterminate, case closed, end of story, take the tents down and clean the cages.  If you give your answer as 1, it's not just incomplete, it's wrong-wrong-wrongity-wrong.

    @RaceProUK said:

    0-1 is undefined, as it becomes division by zero

    -10.5  = i (complex numbers)

     

    And let's see you derive any of those as the result of a loop as was suggested when the thread went in this direction.

    So you wouldn't check for special cases then?

    As for the 00 issue, check this out: http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power. What's more, .NET treats 00 as 1, as do C, C++, Java, and any language that uses IEEE754 floating point arithmatic. Like I said before - both cases are accepted, though context is important.

     



  • @Renan said:

    Also this:

    public class PedanticDickweedery {

      public static int pow (int x, int y) {

        if (y == 0) return 1;

        int originalValue = x;

        for (int i = 0; i < y; i++) {

          x *= originalResult;

        }

        return x;

      }

    }

    Let's assume that line is supposed to be "originalValue *= x" and run it...

    PedanticDickweedery.pow(5,1) == 25?.. Hm...



  • @Sutherlands said:

    Let's assume that line is supposed to be "originalValue *= x" and run it...

    No, that's backwards, unless he were to return originalValue. But the name "originalValue" would be incorrect in that case.

    @Sutherlands said:

    PedanticDickweedery.pow(5,1) == 25?.. Hm...

    I love fence post errors.



  • @TheCPUWizard said:

    @m said:

    @morbiuswilters said:

    What I love is that so many languages have stuck with this despite the fact that I am 14 times more likely to need exponentiation over bitwise operations.
    FTFY

    Wow, was going to post that it would be a bitwise (binary) or, not a decimal digit or....but for this case (and a few others) the two yield the same result.....

     

    Ten is 1010b and four is 0100b

    Ten OR four is 1110b, or decimal 14;   but ten XOR four is 0000b, or zero in any base.

     

    This makes morbs' post a lot funnier:

    @morbiuswilters said:

    What I love is that so many languages have stuck with this despite the fact that I am zero times more likely to need exponentiation over bitwise operations.

    I'm calling it intentional, even if it's not.



  • @Zecc said:

    Ten is 1010b and four is 0100b

    Ten OR four is 1110b, or decimal 14;   but ten XOR four is 0000b, or zero in any base.

    You were right to tag this "I could be wrong". Your supposed-XOR logic is actually either AND or DEAD.



  • @Gurth said:

    @Spectre said:

    Pascal uses **, as well.

    This convinces me even more that the guy teaching me computer stuff in college (a long time ago, and no, it wasn't a computer sciences course :)) didn't know his a$ from his elbow … He had us writing programs in Pascal, and when I (having experience almost exclusively with BASIC at that point) used a^2 in one of them, found it didn't work and asked him about it, did he tell me a**2 would work? No … In the end I went for a*a (which IIRC was not remarked upon by said teacher, incidentally) and wondered to myself if I'd have to do a loop for higher powers.

    This was one of the things that put me off Pascal for good :)

     

    Except that the reality is that Pascal does not have power operator. Maybe some implementations do (e.g. freepascal has operator** defined in the math unit), but definitely not all of them (especially not Turbo/Borland Pascal and Delphi).

     



  • That would explain that, then — it's been far too long to remember what we used, but I suspect it was Turbo Pascal. So the WTF, then, is that you have to write your own function to do such a fairly elementary thing as exponentiation?



  • @Gurth said:

    That would explain that, then — it's been far too long to remember what we used, but I suspect it was Turbo Pascal. So the WTF, then, is that you have to write your own function to do such a fairly elementary thing as exponentiation?

    For Pascal specifically, I agree with this approach. Remember Pascal was originally intended as a teaching language, and not for "real use" and at a time where computing power was much moe limited - hardware floating point was rare.. There are many circumstances where incremental calculations are more efficient han exponentiation (talking about integral exponents) and teaching programmers to think that way was a "good thing".

    Consider there is no need for exponents in (using ^ for exponentiation). X^3 is more efficient by using the previously calculated X^2 and doing one more multiply.

        Y = aX^3+bX^2+c*X+d;



  • @Ibix said:

    @Zecc said:

    Ten is 1010b and four is 0100b

    Ten OR four is 1110b, or decimal 14;   but ten XOR four is 0000b, or zero in any base.

    You were right to tag this "I could be wrong". Your supposed-XOR logic is actually either AND or DEAD.

    Yeah, -1 for myself.

     



  • @Ibix said:

    @Zecc said:

    Ten is 1010b and four is 0100b

    Ten OR four is 1110b, or decimal 14;   but ten XOR four is 0000b, or zero in any base.

    You were right to tag this "I could be wrong". Your supposed-XOR logic is actually either AND or DEAD.

    Pedantic dickweedery commencing: not necessarily. It could be a wide range of logic expression. E.g. f(1010,0100)=0000 also holds true for f(a,b)=b3a2b1b0

    But it's definitely not XOR



  • @dtech said:

    Pedantic dickweedery commencing: not necessarily. It could be a wide range of logic expression. E.g. f(1010,0100)=0000 also holds true for f(a,b)=b3a2b1b0

    But it's definitely not XOR

    Ah yes, I'm sure that instead of mixing up XOR and AND, he instead mixed up XOR with some function that most people on this world have never seen nor used.  Good correction.


  • @dtech said:

    Especially since I think the reason they didn't include a exponential operator in C is because it would increase the size of the compiler, which is not an issue nowadays.

    I dunno about that.  If they really wanted to keep the size and complexity of the compiler down, they wouldn't have overloaded * and &.  The * operator is especially troublesome, because it allows for ambiguous parses.  What does A * B mean?  That depends on the context: is A a type or a variable?  So the parser needs to look at (potentially) the entire stack of symbol tables so it knows which code path to follow.  That's a ton of unnecessary complexity; they could have just gone the Pascal route and used @ and ^, which make more sense mnemonically anyway.  (Oh, wait.  They're already using ^ for something else that it makes no sense for...)

     



  • @da Doctah said:

    If you've got a mathematical expression and it can be manipulated into any of these, it's indeterminate, case closed, end of story, take the tents down and clean the cages. 

    Actually, if you have the actual expresion yes, there is nothing you can do, but if you have an expresion that tends to an indetermination you can sometimes "fix it".  A classic example of this is:

    lim sin(x)/x =1

    x-->0

    The indetermination is 0/0 yet the result of the limit is 1.

    Granted this is very basic but some expresion can be cajoled into several forms that allow resolution as long as the conditions are there.



  • @blakeyrat said:

    Wild ass guess: Mathematica?
    Yup, and MATLAB [my most commonly used language--by necessity, not choice], too!



  • @locallunatic said:

    (For those not doing C# it doesn't use carrot for exponents, but rather bitwise XOR)
     

    [URL=http://imageshack.us/photo/my-images/214/caretcarrot.png/][IMG]http://img214.imageshack.us/img214/15/caretcarrot.png[/IMG][/URL]

     

     


Log in to reply
 

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