## Converting from positive flaot to negative float

## Converting from positive flaot to negative float

(OP)

Hello everybody

I've been tring to find a function or method for converting a posative float like -45.67 to a possative float (45.67). Using the NOT bitwise operator I can convert ints and using the abs function I can convert a negative float to a positive float but it won't work the other way.

I was thinking that I could take a possative number double it and then take that away from the original to get a negative number. E.G if i had the number 14.5 I could double it (29) and then take that from 14.5 and get -14.5 however I don't think this will work for numbers larger than half the maximum range of a float, as the doubling acion will give a number to large for the flaot to hold.

So my question is does any body have siggestions or information on how I might go about changing between posative and negative floats?

Thanks for you time

Andrew

I've been tring to find a function or method for converting a posative float like -45.67 to a possative float (45.67). Using the NOT bitwise operator I can convert ints and using the abs function I can convert a negative float to a positive float but it won't work the other way.

I was thinking that I could take a possative number double it and then take that away from the original to get a negative number. E.G if i had the number 14.5 I could double it (29) and then take that from 14.5 and get -14.5 however I don't think this will work for numbers larger than half the maximum range of a float, as the doubling acion will give a number to large for the flaot to hold.

So my question is does any body have siggestions or information on how I might go about changing between posative and negative floats?

Thanks for you time

Andrew

## RE: Converting from positive flaot to negative float

## CODE

int main()

{

double d = -3.0;

std::cout << d << '\n';

d = -d;

std::cout << d << '\n';

d = -d;

std::cout << d << '\n';

}

## RE: Converting from positive flaot to negative float