Doubling and dividing floating point values

Silverfin

I have the function which I believe will convert an int into a floating point value split into the sign exponent and fraction components of the value. Using IEEE 754 to represent Float values.

enter image description here

unsigned test(unsigned x) {    
    // split the given bits of sign exponent and fraction, combine to return

    unsigned int sign = (x & 0x80000000) >> 31;
    unsigned int expo = (x & 0x7F800000) >> 23;
    unsigned int frac = (x & 0x007fffff);

    return (sign << 31) | (expo << 23) | frac;
}

I'm unsure however how I could compute the halved or doubled values from this floating point representation.

unsigned doubled(unsigned x) {
    // get float
    // float = unsigned int to float
    // doubleFloat  = 2*f
    // if float is not a number
        // return unsigned float
    // else return unsigned integer of half float

    unsigned int sign = (x & 0x80000000) >> 31;
    unsigned int expo = (x & 0x7F800000) >> 23;
    unsigned int frac = (x & 0x007fffff);

    if (expo == 0xff)
        return uf;
    else ...
}
Amadeus

It seems that you are using IEEE 754 to represent Float values.

If you want to double the binary representation, you just need to increment by 1 the expoent. The same is true if you want to half, just decrement by 1

Remember that this is true only if your number is in normal range, including even after doubling or halving

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Doubling and dividing floating point values

From Dev

IBInspectable and floating point values

From Dev

Why does multiplying and dividing by N "fix" floating point representation?

From Dev

x86 Assembly (NASM): Floating Point Exception, not dividing by 0?

From Dev

Why does multiplying and dividing by N "fix" floating point representation?

From Dev

How to get a floating point result from dividing two integers

From Dev

Querying for floating point values in SQLAlchemy

From Dev

Range analysis of floating point values?

From Dev

Floating point values with sin() and sinf()

From Dev

Int overflow with floating point values

From Dev

Range analysis of floating point values?

From Dev

Floating point values with sin() and sinf()

From Dev

Querying for floating point values in SQLAlchemy

From Dev

Convert floating point values to hexadecimal

From Dev

split on integer values but not floating point values

From Dev

dividing floating points into buckets

From Dev

How unreliable are floating point values, operators and functions?

From Java

How dangerous is it to compare floating point values?

From Dev

static compile time table with floating point values

From Dev

Will the scope of floating point variables affect their values?

From Dev

Override equality for floating point values in Scala

From Dev

Xilinx Floating Point Core - Erroneous 'X' values?

From Dev

Is it possible to assign floating point values to enum in java?

From Dev

Printing hexadecimal values in decimal and floating point format

From Dev

Python Pandas alterates values in floating point

From Dev

SWT scale widget - floating point values

From Dev

Dividing uint64_t by numeric_limits<uint64_t>::max() to a floating point representation

From Dev

Floating point error when dividing one small range by another small range

From Dev

Handling endianness of floating point values when there is no fixed size floating point type available

Related Related

  1. 1

    Doubling and dividing floating point values

  2. 2

    IBInspectable and floating point values

  3. 3

    Why does multiplying and dividing by N "fix" floating point representation?

  4. 4

    x86 Assembly (NASM): Floating Point Exception, not dividing by 0?

  5. 5

    Why does multiplying and dividing by N "fix" floating point representation?

  6. 6

    How to get a floating point result from dividing two integers

  7. 7

    Querying for floating point values in SQLAlchemy

  8. 8

    Range analysis of floating point values?

  9. 9

    Floating point values with sin() and sinf()

  10. 10

    Int overflow with floating point values

  11. 11

    Range analysis of floating point values?

  12. 12

    Floating point values with sin() and sinf()

  13. 13

    Querying for floating point values in SQLAlchemy

  14. 14

    Convert floating point values to hexadecimal

  15. 15

    split on integer values but not floating point values

  16. 16

    dividing floating points into buckets

  17. 17

    How unreliable are floating point values, operators and functions?

  18. 18

    How dangerous is it to compare floating point values?

  19. 19

    static compile time table with floating point values

  20. 20

    Will the scope of floating point variables affect their values?

  21. 21

    Override equality for floating point values in Scala

  22. 22

    Xilinx Floating Point Core - Erroneous 'X' values?

  23. 23

    Is it possible to assign floating point values to enum in java?

  24. 24

    Printing hexadecimal values in decimal and floating point format

  25. 25

    Python Pandas alterates values in floating point

  26. 26

    SWT scale widget - floating point values

  27. 27

    Dividing uint64_t by numeric_limits<uint64_t>::max() to a floating point representation

  28. 28

    Floating point error when dividing one small range by another small range

  29. 29

    Handling endianness of floating point values when there is no fixed size floating point type available

HotTag

Archive