[Question]
  [
3D-modeling software mainly uses [UV Mapping](https://en.wikipedia.org/wiki/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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins!
  
[Answer]
# [Python](https://docs.python.org/2/), 20 bytes
```
lambda x:x%1or+(x>0)
```
[Try it online!](https://tio.run/nexus/python2#S7ON@Z@TmJuUkqhQYVWhaphfpK1RYWeg@T85sTi1WMFWIVrXSEfXUM8YSOjo6hnqGOgA2XrmOoY6RjrGepaxXGn5RQoVCpl5CmAdVlycBUWZeSUKFToK6jEl6joKaRoVmv8B "Python 2 ‚Äì TIO Nexus")
Takes the input modulo 1, then handles the boundary case by converting outputs of 0 to 1 for positive inputs. A bool output would save two bytes.
```
lambda x:x%1or x>0
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 14 11 bytes
*Thanks to Fatalize for golfing 3 bytes.*
```
‚àß‚âú:?+.‚â•0‚àß1‚â•
```
For a change, this answer doesn't use mod :)
[Try it online!](https://tio.run/nexus/brachylog2#@/@oY/mjzjlW9tp6jzqXGgB5hkD6//94M0MLPUMjYxNTs/9RAA "Brachylog ‚Äì TIO Nexus")
### Explanation
```
‚àß‚âú                Label an integer variable. This will start trying different
                  values for this variable, the ones closest to 0 first.
   :?+.           This variable summed to the input is equal to the output
      .‚â•0‚àß1‚â•      which is >= 0 and <= 1
```
[Answer]
# JavaScript (ES6), 19 bytes
```
n=>(n%1+1)%1||n>0|0
```
In JavaScript, `n%x` returns a negative number if `n` is negative, meaning that if we want to get the positive residue, we must add `x` if `n` is negative. `(n%x+x)%x` covers all cases:
```
n     n%1   n%1+1 (n%1+1)%1
0     0     1     0
1     0     1     0
2.4   0.4   1.4   0.4
-1    0     1     0
-2.4  -0.4  0.6   0.6
```
Another working solution at 20 bytes, which shows a bit more of a pattern:
```
n=>n%1+(n%1?n<0:n>0)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 9 bytes
```
1&\0>yg>+
```
[Try it online!](https://tio.run/nexus/matl#@2@oFmNgV5lup/3/v5m5hZ6hkbGJqRkA "MATL ‚Äì TIO Nexus") Or [verify all test cases](https://tio.run/nexus/matl#S/hvqBZjYFeZbqf9P8Il5L@uCZeuIZcBlyGXEZehnoGBgSGXmbmFnqGRsYmpGZcuEttEzxQA).
### Explanation
Example with input `678.123456`
```
1      % Push 1
       % STACK: 1
&\     % Implicit input. Divmod with 1
       % STACK: 0.123456, 678
0>     % Is it positive?
       % STACK: 0.123456, 1
y      % Duplicate from below
       % STACK: 0.123456, 1, 0.123456
g      % Convert to logical: nonzero becomes 1
       % STACK: 0.123456, 1, 1
>      % Greater than? This is true if fractional part of input was zero
       % and non-fractional part was positive
       % STACK: 0.123456, 0
+      % Add. Implicitly display
       % STACK: 0.123456
     
```
[Answer]
# Javascript, 28 bytes
```
m=f=>f<0?m(f+1):f>1?m(f-1):f
```
Recursively decreases/increases the values by 1 until the result is in [0,1]
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 8 bytes
```
u1 ¬™UbV1
```
[Test it online!](http://ethproductions.github.io/japt/?v=1.4.4&code=dTEgqlViVjE=&input=Mg==)
I think this is the first time I've ever used `b`...
### Explanation
```
 u1 ¬™UbV1  // Implicit: U = input, V = 0
Uu1        // Take U%1, but add 1 if U is negative. This is equivalent to %1 in Python.
    ¬™      // If the result is falsy (0), instead take
     UbV1  //   U bound between 0 and 1.
           // This converts positive integers to 1, zero/negative integers to 0.
           // Implicit: output result of last expression
```
[Answer]
## Mathematica, 20 bytes
```
#~Mod~1/. 0/;#>0->1&
```
### Explanation
This is a rather unusual use of `/;` where I'm using it more like an `&&` because the condition after it has nothing to do with the pattern it matches.
```
#~Mod~1...
```
Compute `x % 1`, which is correct for all cases except positive integers.
```
.../. 0/;...
```
Replace zeros in the previous expression if...
```
...#>0...
```
...the input is positive...
```
...->1...
```
with `1`.
[Answer]
# PHP, 37 bytes
```
<?=($m=fmod($argn,1))+(!!$m^$argn>0);
```
Run with `echo <number> | php -R '<code>'`.
There are so many ways to do this ... this should be one of the shortest in PHP.
The `fmod` result is negative for negative floats and `0` for positive integers; those need adjustment: `!!$m` is true for floats, xoring with `$n>0` results in false for positive float and negative int, true for negative float and positive int; `+` casts that to `1` or `0` - done.
[Answer]
## C ~~57~~ ~~56~~ 73 bytes
```
b;f(float n){b=n;printf("%f",((!(n-b)&&n<=0)?0:n<0?1.+n-b:(n-b)?n-b:1));}
```
@pinkfloydx33 Thanks for pointing out!
# 
Ungolfed version:
```
f(float n)
{
  int b=n;
  printf("%f",( (!(n-b)&&n<=0)?0:n<0?1.+n-b:(n-b)?n-b:1) );
}
```
[Try it online!](https://tio.run/nexus/c-clang#HYzBCoMwEAXv@YpXobJLa0muRsm3RHGp0K4lxJP42T2n2tswA1OE5LXEDGWzGWDWjKFXb/BJBwtVV6nuRBfSZuC61q63HGyrnQ3ucTtk@y/hJMdgb3ZTzss7zkq8QcixR5rymhTWYy9fXZoxjs/pBw "C (clang) ‚Äì TIO Nexus")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
%1o>0$
```
**[Try it online!](https://tio.run/nexus/jelly#@69qmG9noPL/6J7D7Y@a1rj//x@ta6Kja6hjoGOoY6RjqGdgYGCoY2ZuoWdoZGxiaqaji8Q20TONBQA "Jelly ‚Äì TIO Nexus")**
Jelly has no `True` or `False`, but uses `1` and `0` in their place.
```
%1o>0$ - Main link: float v
%1     - v mod 1
     $ - last two links as a monad
   >0  -     v greater than zero?
  o    - or - replace the 0 result of the mod with 1 when v is greater than 0.
```
[Answer]
# SmileBASIC, 28 bytes
```
INPUT N?N-FLOOR(N)+(N<<0==N)
```
[Answer]
## JavaScript (ES6), 19 bytes
```
n=>(n>0==!(n%=1))+n
```
Explanation: `%1` doesn't give the correct results in all cases:
```
input       %1          output
-ve int     -0
-ve frac    -ve frac    +ve frac
0           0
+ve frac    +ve frac
+ve int     0           1
```
An extra 1 needs to be added in the cases that are wrong, which are those of a negative non-integer and a positive integer. This is what the expression `(n>0==!(n%1))` calculates.
[Answer]
# [><>](https://esolangs.org/wiki/Fish), 26 bytes
```
:1%:?vr1(?v1n;
     >n;n0<
```
[Try it online!](https://tio.run/nexus/fish#@29lqGplX1ZkqGFfZphnzaUAAnZ51nkGNv///9ctUzAAAA "><> ‚Äì TIO Nexus")
Because solutions in *good* golfing languages are almost always pretty instantly given, I decided to mix things up. First <>< answer!
## Explanation
```
:1%:?vr1(?v1n;    Assume input i in stack
     >n;n0<
:                 Duplicate i (need it if i%1 != 0)
 1                Push 1
  %               Pop i and 1, push i%1
   :              Duplicate top of stack because  we need one for the if     
    ?v            If i%1 != 0 ------------------------,
      r           Reverse stack so that i is TOS      | 
       1(?v       If i > 0 (not < 1)                  |
           1n;      Print 1 and Exit                  |
                  Else                                |                   
        n0<         Print 0 and --,                   |
     >n           Print n <-------|-------------------'
       ;          Exit <----------'
```
Fun fact: the explanation is a valid <>< program!
[Answer]
# Javascript, ~~41~~ 28 bytes
```
n=>n-Math.floor(n)+(n<<0==n)
```
`Math.floor()` is so long...
[Answer]
# Pyth, 7 bytes
```
|%Q1s<0
```
Explanation
```
|%Q1s<0
|%Q1s<0Q      Implicitly add input
 %Q1          Input mod 1
|             Short-circuting or
    s<0Q      1 if input is positive, 0 otherwise
```
If you don't mind using True and False as 1 and 0, you can drop the `s` for 6 bytes.
[Answer]
# [Perl 6](https://perl6.org), 15 bytes
```
{+($_%1||$_>0)}
```
[Try it online!](https://tio.run/nexus/perl6#Ky1OVSgz00u25sqtVFBLU7D9X62toRKvalhToxJvZ6BZ@z8tv0hB10RHQddQR8FARwFIGgFJPQMDAyDTzNxCz9DI2MTUDKgAmWOiZ6qga6egkqdQzaUABMWJlQppQK41V@1/AA "Perl 6 ‚Äì TIO Nexus")
Inspired by [seshoumara's comment](https://codegolf.stackexchange.com/questions/111174/mod-the-floats#comment270808_111174) that mod 1 *almost* works.
*EDIT: Ha, [xnor's Python solution](https://codegolf.stackexchange.com/a/111182/14880) beat me to it.*
]