Author Topic: WTF? Divide by 0 on PC Calculator  (Read 2685 times)

Okay, I was making a program to convert from various bases to base 10, and I'm trying dumb things to try to break the program. I try base 0 just to see what it would do.

When I try that, the result is the last digit of the number I put in. I then start wondering why the forget that is.

I look through the code, and what it's doing is multiplying the number from input by the base to the power the digits position starting from the right. It starts at 0 since anything to the power of 0 is 1.

So, I'm like wtf? How is 0^0 = 1? I try it on the calculator, and sure enough, it gives the answer as 1 as well. But my Ti84 says Domain Error.

But X^0 = X/X which is 1. But 0^0 = 0/0 which is a mother loving divide by 0. How in the hell does that work?

Okay, I was making a program to convert from various bases to base 10, and I'm trying dumb things to try to break the program. I try base 0 just to see what it would do.

When I try that, the result is the last digit of the number I put in. I then start wondering why the forget that is.

I look through the code, and what it's doing is multiplying the number from input by the base to the power the digits position starting from the right. It starts at 0 since anything to the power of 0 is 1.

So, I'm like wtf? How is 0^0 = 1? I try it on the calculator, and sure enough, it gives the answer as 1 as well. But my Ti84 says Domain Error.

But X^0 = X/X which is 1. But 0^0 = 0/0 which is a mother loving divide by 0. How in the hell does that work?
Anything to a power of zero is one

Anything to a power of zero is one


Hah, I saw that before you edited. Yes, I know that. But with 0's case, I don't understand it, because to arrive at the answer you must divide by it.


I'm getting 1 on the windows 7 calc and ipod.


Hah, I saw that before you edited. Yes, I know that. But with 0's case, I don't understand it, because to arrive at the answer you must divide by it.


Ill use two as an example
Pattern of powers in two:
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16

So, following that pattern:
2^0 = 1
2^-1 = 0.5
2^-2= 0.25
2^-3 = 0.125
2^-4 = 0.0625

0^0 = 0/0 which is a mother loving divide by 0. How in the hell does that work?

Anything divided by itself is 1, even 0.

I've tested this in a variety of things with 3 different results so far.
0^0 = ...

Windows XP Calculator: 1
Perl: 1
Ti84: Domain Error
C++: 0
Visual Basic: 1

-snip-
*Sarge is not smart enough to process this equation. Initializing shut-down.

It's math like this that makes me happy. :3

I love how we give him answers and he ignores them

I love how we give him answers and he ignores them

Because the answers don't help at all. Different programming languages/programs disagree on the answer so I don't see how anyone on here could really give a definite answer either.

Google calc says 1. So its 1.

Enter 0^0= into google

I love how we give him answers and he ignores them
i saw the answers, but i tried doing the math by myself. i borked

0/0=-1 #INF
0x0=0
0^0=0
Simple math.

Code: [Select]
while(1) {
$answer = 0;
print "Number to convert?\n";
  chomp($input = <STDIN>);
print "Base to convert from?\n";
  chomp($base = <STDIN>);
print "Base to convert to?\n";
  chomp($base2 = <STDIN>);
while($base > 62 or $base < 2) {
if($base > 62) {
print "ERROR: Base cannot exceed 62!\n";
}
if($base < 2) {
print "ERROR: Base cannot be lower than 2!\n";
}
chomp($base = <STDIN>);
}
while($base2 > 62 or $base2 < 2) {
if($base2 > 62) {
print "ERROR: Base cannot exceed 62!\n";
}
if($base2 < 2) {
print "ERROR: Base cannot be lower than 2!\n";
}
chomp($base2 = <STDIN>);
}
print "\nBASE $base: $input\n";
for($i = length($input) - 1; $i >= 0; $i--) {
$sub_input = substr($input,$i,1);
if($sub_input =~ /A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z/){
$sub_input = ord("$sub_input") - 55;
}
if($sub_input =~ /a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z/){
$sub_input = ord("$sub_input") - 61;
}
$answer += $sub_input * ($base ** (($i - length($input) + 1) * -1));
}
print "BASE 10: $answer\n";
$output = "";
$i = $base2;
while($i < $answer) {
$i = $i * $base2;
}
while($i >= 1) {
if($answer < $i) {
$output .= "0";
}
else {
$fix = $answer%$i;
$fix = $answer - $fix;
$num = $fix/$i;
$answer -= ($i * $num);
if($num <= 9) {
$output .= $num;
}
if($num > 9 and $num <= 35) {
$num2 = $num + 55;
$output .= chr("$num2");
}
if($num > 35) {
$num2 = $num + 61;
$output .= chr("$num2");
}
}
$i = $i/$base2;
}
$out2 = "";
if(substr($output,0,1) eq "0") {
for($j = 1; $j<= length($output); $j++) {
$out2 .= substr($output,$j,1);
}
print "BASE $base2: $out2\n\n";
}
else {
print "BASE $base2: $output\n\n";
}
}

Here's the base converter I made. It's written in perl and can convert from any base between 2 and 62.

Code: [Select]
use Tk;
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Console;
Win32::Console::Free( );
}
}
my $main_window = new MainWindow;
my $frame = $main_window -> Frame();
my $lab = $frame -> Label(-text=>"(Original) Base: 2");
my $ent = $frame -> Text(-width=>50, -height=>3);
my $srl_y = $frame -> Scrollbar(-orient=>'v',-command=>[yview => $ent]);
$srl_y -> grid(-row=>2,-column=>8,-sticky=>"ns");
$ent -> configure(-yscrollcommand=>['set', $srl_y],);
my $lab2 = $frame -> Label(-text=>"Base: 10");
my $ent2 = $frame -> Text(-width=>50, -height=>3);
my $srl_y2 = $frame -> Scrollbar(-orient=>'v',-command=>[yview => $ent2]);
$srl_y2 -> grid(-row=>3,-column=>8,-sticky=>"ns");
$ent2 -> configure(-yscrollcommand=>['set', $srl_y2],);
my $lab3 = $frame -> Label(-text=>"(New) Base: 2");
my $ent3 = $frame -> Text(-width=>50, -height=>3);
my $srl_y3 = $frame -> Scrollbar(-orient=>'v',-command=>[yview => $ent3]);
$srl_y3 -> grid(-row=>4,-column=>8,-sticky=>"ns");
$ent3 -> configure(-yscrollcommand=>['set', $srl_y3],);
my $but = $main_window -> Button(-text=>"Convert!", -command =>\&move_slider);
$but -> grid(-row=>5,-column=>1,-columnspan=>2);
my $scl = $frame -> Scale(-label=>"Original Base :",
-orient=>'h', -digit=>1,
-from=>2, -to=>62,
-variable=>\$base, -tickinterval=>0, -length => 200, -command => \&move_slider);
$scl -> grid(-row=>1,-column=>1);
my $scl2 = $frame -> Scale(-label=>"New Base :",
-orient=>'h', -digit=>1,
-from=>2, -to=>62,
-variable=>\$base2, -tickinterval=>0, -length => 200, -command => \&move_slider);
$scl2 -> grid(-row=>1,-column=>2);
$lab -> grid(-row=>2,-column=>1);
$ent -> grid(-row=>2,-column=>2);
$frame -> grid(-row=>1,-column=>1,-columnspan=>2);
$lab2 -> grid(-row=>3,-column=>1);
$ent2 -> grid(-row=>3,-column=>2);
$lab3 -> grid(-row=>4,-column=>1);
$ent3 -> grid(-row=>4,-column=>2);
MainLoop;
sub move_slider {
$lab -> configure(-text=>"(Original) Base: $base");
$lab3 -> configure(-text=>"(New) Base: $base2");
$answer = 0;
my $input = $ent -> get('1.0','end');
for($i = length($input) - 1; $i >= 0; $i--) {
$sub_input = substr($input,$i,1);
if($sub_input =~ /A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z/){
$sub_input = ord("$sub_input") - 55;
}
if($sub_input =~ /a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z/){
$sub_input = ord("$sub_input") - 61;
}
$answer += $sub_input * ($base ** (($i - length($input) + 2) * -1));
}
$ent2 -> delete('0.0', 'end');
$ent2 -> insert('end',"$answer");

$output = "";
$i = $base2;
while($i < $answer) {
$i = $i * $base2;
}
while($i >= 1) {
if($answer < $i) {
$output .= "0";
}
else {
$fix = $answer%$i;
$fix = $answer - $fix;
$num = $fix/$i;
$answer -= ($i * $num);
if($num <= 9) {
$output .= $num;
}
if($num > 9 and $num <= 35) {
$num2 = $num + 55;
$output .= chr("$num2");
}
if($num > 35) {
$num2 = $num + 61;
$output .= chr("$num2");
}
}
$i = $i/$base2;
}
$out2 = "";
if(substr($output,0,1) eq "0") {
for($j = 1; $j<= length($output); $j++) {
$out2 .= substr($output,$j,1);
}

$ent3 -> delete('0.0', 'end');
$ent3 -> insert('end',$out2);
}
else {
$ent3 -> delete('0.0', 'end');
$ent3 -> insert('end',$output);
}
}

And there's an extremely ugly Perl TK version.