# Mod the Floats!

3D-modeling software mainly uses UV Mapping to map textures onto a 3D object. The valid values for both U and V are usually located in an inclusive [0..1] range.

## Challenge

You bought a new 3D-modeling software which is super-easy to use. However there is one issue with it: it adds or subtracts a random integer number from UV values. Your task is to create a program or a function that modifies an input value to get a float value in an inclusive [0..1] range.

The resulting float should have the same fractional part as the original, and be as close to the original as possible. Because both 0 and 1 are in the output range, any integers 0 or less should change to 0, and any integers 1 or greater should change to 1.

An example algorithm in JavaScript:

function modFloat(input) {
while (input < 0 || input > 1) {
if (input < 0) input += 1;
if (input > 1) input -= 1;
}
return input;
}

## Rules

• Input is a single integer or float value. Any reasonable format is allowed as long as it is specified in your answer.
• The output should be a decimal representation of a float value.
• The output precision should be at least same decimal places as input.
• Trailing zeros are allowed.
• Be sure your code correctly chooses which of 0 or 1 to output for integer inputs.

## Test cases

Input       | Output
------------+---------
-4 | 0
-1 | 0
0 | 0
1 | 1
2 | 1
1.0001 | 0.000100
678.123456 | 0.123456
-678.123456 | 0.876544
4.5 | 0.5

This is , so the shortest code in bytes wins!

• Do you intend for 1 to map to 1? Usually a half-open range is used. Based on your pseudocode, should I understand all integers >1 go to 1, and all integers <0 go to 0> – xnor Feb 24 '17 at 16:50
• All %1 solutions fail if input is 1! – seshoumara Feb 24 '17 at 16:51
• Actually, I like the 1->1 thing, it keeps the problem from being a trivial built-in for many languages. – xnor Feb 24 '17 at 16:52
• Can I use sed for this? There are no data types in sed, the input would have to be a text stream. – seshoumara Feb 24 '17 at 17:16
• @seshoumara any reasonable input format is allowed, so I'd say "Why not?". – lolbas Feb 24 '17 at 17:27

%1o>0$Try it online! Jelly has no True or False, but uses 1 and 0 in their place. %1o>0$ - Main link: float v