1

Anyone know how to square a negative value in perl? It doesn't seem to work no matter what we've tried

Comments
  • 2
    I don't know Perl, but a the very worst I don't understand how something like (-x)*(-x) could not work !
  • 0
    @willol well that does work but I'm talking about specifically squaring, the program we're using is designed as an algebra based homework study guide that we use at our university so based and the formula used as part of the general form of a quadratic equation this entails squaring the value and it just looks rather odd that we can't square it even though multiplying the same negative integer to itself does produce the correct result

    Like I said this only occurs with negatives however and we're beginning to think it's something directly related to Perl itself
  • 0
    Never had that problem on perl, but if it's squaring shouldn't be same x*x as -X*-X?
  • 0
    print -2*-2 works for me,what error do you get?
  • 0
    @nbamaral the issue isn't the end execution, we wanted to follow the exact format used in order to show the students exactly how the formula is applied this is more presentation I suppose
  • 0
    Ah, ok, yes I was reading perlop, (-3)**2 should work, from what I understand, it doesn't.
    Have tried perlmonks? Not many perl people here 😀
    @Damgecontrol
  • 0
    Something like
    $a=-3;
    print $a**2;
    Does work, there must be some syntax trick I don't know 😛
Add Comment