I have a variable x
of type float
, and I need its fractional part. I know I can get it with
x - floorf(x)
, orfmodf(x, 1.0f)
My questions: Is one of these always preferable to the other? Are they effectively the same? Is there a third alternative I might consider?
Notes:
- If the answer depends on the processor I'm using, let's make it x86_64, and if you can elaborate about other processors that would be nice.
- Please make sure and refer to the behavior on negative values of
x
. I don't mind this behavior or that, but I need to know what the behavior is.