Negation of an Arbitrary Number: Challenge!
Topic: Negation of an Arbitrary Number: Challenge!
(Read 2655 times)
Re: Negation of an Arbitrary Number: Challenge!
Oct 16, 2011, 11:51 pm
Looks pretty good. But what if I have an arbitrary data type, too? A byte, for example, wouldn't work with your function. So without using something like a template, can it be done with a single, one-line function that works for all real numbers? (It's really more of a math problem than a CS/programming question...)
p.s. I think I have an idea... It involves the sign() function, which is not commonly used in mathematics (but it is allowed here, as are other math functions... sin, cos, tan, etc.) Also, the sign() function can be (sort of) represented by abs(x)/x (but it doesn't work for zero). That is your hint. Maybe a
graph of the sign function
For a big hint:
Graph from wolfram|alpha
Try substituting 0 in for x... see what happens.