Quote:Original post by all_names_taken
A general solution to the problem most likely requires bitwise operations with the binary representation of the floating point number, and would become a rather large function with several conditional statements and maybe also some loops.
Actually, splitting a float into its sign, exponent and significand pieces using bitwise operations is pretty easy. I've done it before. From there it's a simple decrement to the significand, and if necessary decrement the exponent. No loops required, and not even that many lines of code.
However as I've already stated, there are functions in <cmath> that do this work for you. One function separates out the significand and exponent, and one combines these back together. Using these you can do the whole thing in 3 lines of code.
There's your general solution.