Pages: 1 [2]   Go Down
Author Topic: Negation of an Arbitrary Number: Challenge!  (Read 1128 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
Karma: 17
Posts: 1216
RTFD (Datasheet in our case)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice @robtillaart!

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 will help.

For a big hint:
Graph from wolfram|alpha Try substituting 0 in for x... see what happens.


Pages: 1 [2]   Go Up
Jump to: