Design a function f(f(n)) == -n

Where n is a 32 bit signed integer.

Complex numbers arithmetic are forbidden.

Design it for the largest range possible, knowing that you can’t design it for the whole range of numbers.

The solution is to use Math Ceiling :

static double F(double n){
if (n == 0) return 0;
if (n < 0) return ((long)Math.Ceiling(n) % 2 == 0) ? (n + 1) : (-1 * (n - 1));
else return ((long)Math.Floor(n) % 2 == 0) ? (n - 1) : (-1 * (n + 1));

Related posts:

Could not instantiate mail function on WordPress
If you get the “Could not instantiate mail function” message when you try the contact page in WordPress, that means that you have an issue ...
Functioning of wind turbines
The electric power delivered by a wind turbine depends on the length and shape of its blades, the temperature that will vary the density of ...
The best multifunction color laser printers
Here is the list of the best multifunction printers with laser technology and which print in color. The reviews come from several online ...
Top of the multifunction color laser printers
Here are the top two of the most efficient multifunction color laser printers and a brief description for both of them. Color laser printer ...
The best multifunction black and white laser printer
List of the best laser printers with scanner that print in black and white. PPM : pages per minutes. Reviews: reviews from different online ...