stephanm has asked for the wisdom of the Perl Monks concerning the following question:
To demonstrate - here is some code:
The output looked like this:print "Power of calculation test\n"; print("line 1: ", -4**1.5, "\n"); print("line 2: ", (-4)**1.5, "\n"); print("line 3: ", 1/(-4)**1.5, "\n"); print("line 4: ", 3 + (-4)**1.5, "\n");
Power of calculation test line 1: -8 line 2: 0 line 3: 0 line 4: 0
So, the line 1 output is probably explained by precedence.
However, if line 2 is a permissible operation - how does it get to zero?
And why (line 3) can I use the result as a divisor without Perl complaining about division by zero or add 3 and still get zero?
It cost me a few hours to find why my numbers did not add up - shouldn't (-4)**1.5 be an illegal statement?
Appreciate your wisdom...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Strange Logic in Power of arithmetic
by Athanasius (Archbishop) on Jan 12, 2016 at 13:11 UTC | |
by choroba (Cardinal) on Jan 12, 2016 at 13:18 UTC | |
by hotchiwawa (Scribe) on Jan 12, 2016 at 13:22 UTC | |
|
Re: Strange Logic in Power of arithmetic
by Your Mother (Archbishop) on Jan 12, 2016 at 13:50 UTC | |
|
Re: Strange Logic in Power of arithmetic
by ExReg (Priest) on Jan 12, 2016 at 15:59 UTC | |
by 1nickt (Canon) on Jan 12, 2016 at 16:03 UTC | |
by ExReg (Priest) on Jan 12, 2016 at 16:18 UTC | |
|
Re: Strange Logic in Power of arithmetic
by VinsWorldcom (Prior) on Jan 12, 2016 at 14:50 UTC | |
by stephanm (Sexton) on Jan 27, 2016 at 12:08 UTC | |
by syphilis (Archbishop) on Jan 27, 2016 at 13:00 UTC |