how about the behaviour of your function for input between a multiple of hundred and that value+1?
As an example: the original code doesn’t assign a value to OutVal for val=100.5. Your refactored code assigns a value OutVal=100 to it.
Good find! I do not know what the intentions of the original author were. I suspect that was an error in the original implementation, though we never discussed it. They may have also assumed integer input.
I remember coming up with this method for one of the ol’ Monday Math Madnesses. You can use floor(Val/100), etc to extract digits from a multidigit number after subtracting out higher orders. It’s not entirely refactoring because I didn’t find anyway to do it before, but uses a similar concept.
Hi Doug,
how about the behaviour of your function for input between a multiple of hundred and that value+1?
As an example: the original code doesn’t assign a value to OutVal for val=100.5. Your refactored code assigns a value OutVal=100 to it.
–Han
Han,
Good find! I do not know what the intentions of the original author were. I suspect that was an error in the original implementation, though we never discussed it. They may have also assumed integer input.
Doug
I remember coming up with this method for one of the ol’ Monday Math Madnesses. You can use floor(Val/100), etc to extract digits from a multidigit number after subtracting out higher orders. It’s not entirely refactoring because I didn’t find anyway to do it before, but uses a similar concept.
careful indexing could be applied to scale for much larger numbers.