WeBWorK Problems

Squaring negative numbers using "Compute"

Re: Squaring negative numbers using "Compute"

by Hedley Pinsent -
Number of replies: 0
Thanks Brian and Alex (Jordan)

It's all sorted out now.

Alex's comments made it to my mailbox but not the forum (presumably a technical issue) and I have taken the liberty of including them below. The only thing I will add is that Compute($h **2) works but Compute($h^2) will not.

So many layers - so exciting - I think I will not think about it too much and let it seep in.

hp

Hi Hedley,

When you use:
Compute ("$h **2");
The quotes are turning "$h **2" into a string first, by turning each Perl variable into its string format. So you are actually asking for:
Compute ("-4 **2");
which should be -16.
Instead, I think you could use:
Compute ("($h) **2");
or
Compute ($h **2);
or
Real($h **2);

Alex