I am doing some programming with math. I have written a tidy function which turns any positive number to negative or any negative number to a positive.

I would like to name this function in the most informative way so that if someone else were to look at my function; they would understand, straight away, what it does (and expect what it says on the tin).

The best word I can come up with is 'flip' but I feel that it fails at being obvious.

The function belongs to the Math object so it looks like this:

answer = Math.flip(number)

The results might be

-1 = Math.flip(1)


1 = Math.flip(-1)

How can I best describe this act?

  • My calculator uses CHS ( change sign).
    – Jim
    Jun 25, 2015 at 23:52
  • Most if not all programming languages don't have a name for this function because it is achieved by simple use of the minus sign: 1 = - (-1). I hope you aren't really having to write a function that does that.
    – Avon
    Jun 26, 2015 at 0:00
  • What @Avon said. But if you really wanted to implement such a function, negate would surely be a natural name for it. negate(-1) returns +1, obviously. Jun 26, 2015 at 0:01
  • @FumbleFingers negate's good but it has, sort of 'nullify' connotations to me. How about minus(1)?
    – Avon
    Jun 26, 2015 at 0:03
  • Interestingly, x *= -1; is regarded on stackoverflow as the best way to do it in Java (stackoverflow.com/questions/7869911/…). Horrifyingly, x = x * -1 is regarded as the best way in C# (stackoverflow.com/questions/1348080/…) and x = System.Math.Abs(x) * (-1); comes in second. I think people might have been poking fun there.
    – Avon
    Jun 26, 2015 at 0:17

1 Answer 1



1.3 chiefly Mathematics Subject to inversion; transform into its inverse.


but it has lots of meanings in maths. More precisely, it is the Additive Inverse

the additive inverse of a number a is the number that, when added to a, yields zero

and not to be confused with Multiplicative Inverse

a multiplicative inverse or reciprocal for a number x, denoted by 1/x or x−1, is a number which when multiplied by x yields the multiplicative identity, 1


So... err... invert additively? It's not very good, sorry.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.