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 10^{x}?

@Rhywden said:
I'm not sure, but is there actually a language which does not require using a function to calculate something like 10^{x}?
Brainf*ck.

@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 10^{x}?
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 10^{x}?
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 poorlyformed, decadesold 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, objectoriented, dynamic scripting language should look like something dropped out of the assend 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 10^{x}?
Python does that:
>>a = 3 >>10**a 1000
It even has support for complex numbers:
>>(10)**1.1 (11.9730921641640263.89029346894877j)

@Rhywden said:
I'm not sure, but is there actually a language which does not require using a function to calculate something like 10^{x}?
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 10^{x}?
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:
And as mentioned above, FORTRAN, which is probably why it's also available in PL/I.I'm not sure, but is there actually a language which does not require using a function to calculate something like 10^{x}?
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).

@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 10^{x}?
IIRC Fortran used ** as the exponentiation operator
Used? I'm pretty sure Fortran still exists.
Pascal uses
**
, as well.

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

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 10^{x}?
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.
FTFYWow, 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 10^{x}?
$ perl E 'say 103;'
1000I 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?

@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 welldefined. 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 10^{x}?
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 Csyntax languages doing it for the sort of "backwardcompatibility" (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 welldefined. 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:
 0^{0}
 0^{1}
 1^{0.5}
 0^{0}

0^{0} could be 1, or it could be indeterminate  both are accepted
0^{1} is undefined, as it becomes division by zero
1^{0.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 10^{x}?
IIRC GlovePIE not only uses ^ for exponation, but ^^ for tetration.

@RaceProUK said:
0^{0} could be 1, or it could be indeterminate  both are accepted
Not in my neighborhood they're not. 0^{0 }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 wrongwrongwrongitywrong.^{ }
@RaceProUK said:
0^{1} is undefined, as it becomes division by zero
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.1^{0.5} = i (complex numbers)

@da Doctah said:
@RaceProUK said:
0^{0} could be 1, or it could be indeterminate  both are accepted
Not in my neighborhood they're not. 0^{0 }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 wrongwrongwrongitywrong.^{ }
@RaceProUK said:
0^{1} is undefined, as it becomes division by zero
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.1^{0.5} = i (complex numbers)
So you wouldn't check for special cases then?
As for the 0^{0} issue, check this out: http://en.wikipedia.org/wiki/Exponentiation#Zero_to_the_zero_power. What's more, .NET treats 0^{0} 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:
Let's assume that line is supposed to be "originalValue *= x" and run it...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;
}
}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.
FTFYWow, 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 supposedXOR 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:
Yeah, 1 for myself.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 supposedXOR logic is actually either AND or DEAD.

@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 supposedXOR 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)=b_{3}a_{2}b_{1}b_{0}
But it's definitely not XOR

@dtech said:
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.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)=b_{3}a_{2}b_{1}b_{0}
But it's definitely not XOR

@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 languageby 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/myimages/214/caretcarrot.png/][IMG]http://img214.imageshack.us/img214/15/caretcarrot.png[/IMG][/URL]