News:

;) This forum is the property of Proton software developers

Main Menu

Convert to negative float number

Started by jpeeters19, Sep 14, 2021, 08:40 AM

Previous topic - Next topic

jpeeters19

is there an easy way to convert a float variable from positive to negative?
I am now using the following code:
floatNumber = 0 - FloatNumber

top204

#1
MyFloat = -MyFloat

The compiler uses a highly optimised method of changing a floating point variable's sign. For example, with a 14-bit core device it uses the assembler code:

    movlw 128
    xorwf MyFloatH,F

With an 18F device it uses:

    btg MyFloatH,7,0