githublog icon indicating copy to clipboard operation
githublog copied to clipboard

Minor quibble on

Open gcardwel opened this issue 1 year ago • 0 comments

Minor quibble with the excellent writeup fast-inverse-sqrt.md.

You write:

An IEEE-754 32-bit float can be regarded as a struct, which holds 3 members. Using C's bit-field notation here:

struct float_raw {
  int32_t mantissa : 23;
  int32_t exponent : 8;
  int32_t sign     : 1;
}

But, in fact, what you really want is this:

An IEEE-754 32-bit float can be regarded as a struct, which holds 3 members. Using C's bit-field notation here:

struct float_raw {
  uint32_t mantissa : 23;
  uint32_t exponent : 8;
  uint32_t sign     : 1;
}

because if you used signed, you will get some interesting behavior with sign extension as per https://stackoverflow.com/questions/42527387/signed-bit-field-represetation and others.

One notable thing is that while fast inverse square root is quite useful in graphics, it's also applicable to calculation of fluid flow as a function of pressure difference.

gcardwel avatar Jan 10 '25 05:01 gcardwel