-6
0
Target:
Write a floor()
function from scratch.
Manipulating like converting float to string, and cutting all after dot are allowed.
All languages are allowed.
Any usage of built in language functions (like toInteger()
) or similar is not allowed, casting operators are not allowed.
So, your task is implement floor() function without using casting and built in language functions.
Your function must support at least max 32-bit integer values (you will never receive negative values).
Forced casting (like somevar as float
) and normal casting - such as(int) somevar
-
is not allowed, any built in functions, not allowed, all other stuff allowed.
Winner: Shortest implemention.
2This is severely underspecified. 1. Which input range do we have to support. In particular, can the input be negative? 2. What exactly does built in language functions(like tointeger()) or something like this mean? I assume casting to integer is forbidden as well, but what about operations that simply return an integer (e.g., integer division by 1)? 3. C returns an integral floating point number, not an integer. Any hypothetical
tointeger()
would probably do something else. – Dennis – 2017-05-22T19:25:46.643@Dennis, sorry for underspecifies. I fix some problems of question – None – 2017-05-22T19:40:10.543
4Casting is still unclear. Unless we are forced to return an integral float, we'll have to cast at some point. Also, does max int32 values refer to the maximal signed or the maximal unsigned integer? It might be clearer if you just state the limits in decimal. – Dennis – 2017-05-22T19:43:22.203
@Dennis, fixed all – None – 2017-05-22T19:54:11.387
Can the result have a leading dot and zeroes (eg
5.67
->5.00
) – dzaima – 2017-05-24T19:52:28.557