There are many answers on how to separate fractional part from integer part in float, but is there a way to efficiently assemble float from 2 integer numbers? For example, 123 and 012345 will produce 123.012345 (doesn't have to be exact)
This question was after reading "How to parse space-separated floats in c++ quickly" where the linked answer uses the following approach to assemble floats:
- using
strtol
extract number from left of the '.' (will be the integer), extract the number on the right of the '.' (will be the fractional part) - using the length of second number, multiply the number by 0.1, 0.01, 0.001, 0.0001 depending on its length
- add left to right.
Is there a more efficient approach (in c++ 14 and above)? Currently it requires multiplication and addition, which can play role when assembling hundreds of millions of such numbers.
... Something that would set exponent and mantissa directly?
Edit:
regarding distinguishing 012345 from 12345 when it's in the int form, the author of the above link used strtol, so I can compute the length we travelled while parsing. So I would know that the number is 6 digits long (for example), even though I got 12345