I think we are at max reply depth but here is the trivial dynamically typed solution to the problem:
https://pastebin.com/UZvB5YD1
It's a little bit simpler than anything you will get in an statically typed language. It works for integer and floats of any size. It even works for lists!
You can't do that in a statically typed language without a ton of code.