# Is it a whole number?

A number is whole if it is a non-negative integer with no decimal part. So 0 and 8 and 233494.0 are whole, while 1.1 and 0.001 and 233494.999 are not.

## Input

A floating-point number in the default base/encoding of your language.

For example, the default integer representation for Binary Lambda Calculus would be Church numerals. But the default integer representation for Python is base 10 decimal, not Unary.

## Output

A truthy value if the input is whole, a falsy value if it is not.

Note that if your language only supports decimal precision to, say, 8 places, 1.000000002 can be considered whole.

Input and output may be done via any standard I/O methods.

# Test cases

Input        -> Output
332          -> true
33.2         -> false
128239847    -> true
0.128239847  -> false
0            -> true
0.000000000  -> true
1.111111111  -> false
-3.1415926   -> false
-3           -> false


# Scoring

As with , the shortest submission wins. Good luck!

• @StephenLeppik It's no easier than the vanilla parity challenge, or the Hello World, or the Truth Machine. (In fact, it's harder than most of those.) Nov 18, 2017 at 3:28
• May we take input as two numbers, representing a fraction? Nov 18, 2017 at 3:32
• @LyricLy No, that would either be much easier for some languages or unnecessary for others. Nov 18, 2017 at 3:35
• Note that whole numbers are non-negative integers. Please update your first sentence to reflect this. And you can add in negative numbers test cases if you wish to show how whole numbers are not negative and falsy outputs for negative numbers are valid. Nov 18, 2017 at 3:56
• @ThomasWard, that wikipedia article seems to not fully agree with you: "Texts that exclude zero from the natural numbers sometimes refer to the natural numbers together with zero as the whole numbers, but in other writings, that term is used instead for the integers (including negative integers)". I read the title as asking about integers. Nov 20, 2017 at 9:02

# Retina, 12 10 bytes

Match the format of a non-negative whole number

^\d+\.?0*$ Try it online -2 thanks to FryAmTheEggman # Jelly, 3 bytes ḞA=  Try it online! The algorithm is the same as the one used in the Mathematica answer above. • No, it's not a bug that you can't explicitly state a 0 integer part, it's a feature, and specifically a syntax rule that dictates that a leading 0 is a 0 on its own, so for example 053 is the same as 0 53 and 0.5 is the same as 0 .5. Nov 18, 2017 at 9:42 • @EriktheOutgolfer Nice. But when will you need 2 consecutive nilad? Nov 18, 2017 at 9:52 • A couple of cases would be a dyad-nilad pair followed by a nilad-dyad pair and a quick which takes multiple nilads in a row (specifically ƭ = tie), and a third case would be something like a trailing (dyad)(nilad)(nilad) or (monad)(nilad) or (dyad)(nilad)(nilad)(monad) or even (monad)(nilad)(monad) etc. Nov 18, 2017 at 10:00 • @EriktheOutgolfer Apparently ƭ is one of the quicks that does not have syntax specification... / What does those trailing do? Nov 18, 2017 at 10:09 • All the detail about how Jelly interprets the "input" (the code in your footer) is only necessary because of your test-suite implementation (using Jelly code to give the numbers) if you use an argument it is evaluated as Python code - see this for example. Nov 18, 2017 at 13:54 # Ruby, 17 bytes ->n{n>=0&&n%1==0}  Try it online! It's not great, but I don't think it can get smaller. # R, 30 22 bytes a=scan();if(a%%1==0&a>0,T,F)  • It's a pity that we can't take strings as input, because grepl("^\\d+.?0*$",scan(,"")) is 29 bytes. Ah well, +1. Nov 20, 2017 at 19:25
• You don't need the if: a=scan();a>0&!a%%1 works for 18 bytes. Jun 8, 2021 at 9:05

# Implicit (version predating challenge), 10 bytes

÷±1>?{;;ö}


Try it online! (Will only work after Dennis pulls TIO for the eighteenth time, bugs are stupid)

÷±1>?{;;ö}   no implicit input :(
±1          push -1
>         push (input > -1)
?{...}   if truthy
;      pop (input > -1)
;     pop -1
ö    push iswhole(input)
implicit integer output.
if (input > -1) was false, it prints (input > -1).
otherwise, it prints iswhole(input).


Posting this as an alternate solution since I had to update the builtin after realizing that whole numbers are >= 0, which feels cheaty.

# Implicit, 1 byte

ö


Do no other languages have this builtin?!

   implicit float input
ö  push truthy if whole, falsy otherwise
implicit int output


# Brachylog, 7 bytes

⌋₁ℕ.&⌉₁


Try it online!

At first, I expected to submit a one-byte answer ℕ, which is a predicate meant to be equivalent to an assertion that the input (which is the output variable as well) is a whole number. Turns out, it doesn't consider integer-valued floats to be integers (throwing a false negative on the 0.00000000 test case, as well as the 1.0 non-test-case), so I had to do this instead:

           The input
⌋₁         rounded down
ℕ        which is non-negative
.       is the output variable
&      and the input
⌉₁    rounded up
is also the output variable.

• Any number with a decimal separator is a float. Mar 7, 2019 at 7:48

# ><>, 10 bytes

:1%$0(+0=n  Try it online! Explanation Calculates (n%1 + n<0) == 0 # TI-BASIC (TI-84), 3 bytes not(fPart(Ans  Example: 3.5 3.5 not(fPart(Ans 0 21 21 not(fPart(Ans 1  Built-in functions are amazing, no? Prints 0 (false) if Ans has a decimal part or 1 (true) if it doesn't. # Recursiva, 4 bytes =aIa  Try it online! # MY, 8 bytes ω≥ωω⌊=∧←  Try it online! The link uses arrays to test multiple numbers at once. ## How? • ω≥ = ω>=0 (0 is popped when stack is empty) • ωω⌊= = ω==floor(ω) • ∧← = take the logical and of the things above, then output. # Clojurescript, 12 bytes #(=(int %)%)  No TIO, this doesn't work in Clojure, only Clojurescript. You can try it here though: cljs.user=> (def f #(=(int %)%)) #'cljs.user/f cljs.user=> (f 2) true cljs.user=> (f 2.0) true cljs.user=> (f 2.5) false  # Python 3, 5957 48 bytes print("1")if float(input())%1==0else print("0")  Try it • Welcome to the site! You don't have to explicitly output true and false, instead you can output any two distinct values, such as 1 and 0, that are the same as true and false. Also, this answer can be golfed by removing unnecessary whitespace, and other such tricks found here Nov 18, 2017 at 12:46 • Fails for negative integers (the requirement is to treat these as not-whole numbers). Nov 18, 2017 at 14:40 • Note that eval is shorter than float and will suffice here. Also you can put the if inside your print: print("1"if eval(input())%1==0else"0"). Furthermore you could use string indexing: print("01"[eval(input())%1==0]). But we don't need "1" and "0" at all: print(eval(input())%1==0). A lambda would then save more: lambda n:n%1==0 (not that any of this fixes the issue I noted above). Nov 18, 2017 at 14:46 • Why not just print the boolean directly? print(float(input())%1==0) Although the negative integer problem is pretty major. Nov 19, 2017 at 7:58 ## D : 43 bytes Just discovered that D has strange cast rules. Code : int w(float n){return n==cast(int)n&&n>=0;}  ### For testing D Code : void main() { float[] f = [ 332,33.2f,128239847,0.128239847f,0,0.0000f,1.1111111111f,-3.1415926f,-3 ]; for (int t = 0; t < f.length; ++t) { writeln(f[t]," = ", w(f[t])?"true":"false"); } }  • Yeah, D has some weird casting rules for sure. Nov 19, 2017 at 1:05 # PowerShell, 24 bytes +"$args"-match'^[^-.]+$'  Try it online! Convert the argument to a string, then back to a number (actually unnecessary, could have also just used $args[0] directly, but I thought of the latter first and it's the same byte count), then do a regex match, looking to see that the string has no - or . characters in its entirety.

Simple and boring :(

# PHP, 28 bytes

First solution:

echo!(ceil($n=$argv[1])-$n);  Second solution: echo floor($n=$argv[1])==$n;

• gives false positive for every negative int Nov 19, 2018 at 21:37

# Pyth - 10 Bytes

&qQ.EQgQ0


Explanation :

              Implicitly Print
&              And
q           Are Equal
Q        Input
.E       Ceiling of
Q     Input
g           Greater Than or Equal to
Q        Input
0         0


## Hexagony, 6 bytes

?~<%@'


Try it online!

Output via exit code. 1 for whole numbers and 0 otherwise.

### Explanation

Unfolded:

 ? ~
< % @
' .


If we try to read two integers, then the second one will be zero for whole numbers.

?    Read whole number part, N.
~    Multiply by -1.
<    This branches depending on whether the value is positive or not, i.e.
whether N is negative or not.

If it's negative, the IP moves SE.

'    Move the memory pointer backwards, to the right.
%    Computes (0 % N). Irrelevant.
~    Multiply by -1. Irrelevant.
@    Terminate the program.

If N isn't negative, the IP moves NE from the <.

?    Read the fractional part, F.
'    Move the memory pointer backwards, to the right.
%    Computes (0 % F). This terminates the program with exit code 1 if
F is zero. Otherwise, it does nothing.
~    Multiply by -1. Irrelevant.
<    Reflect the IP to SW.
~    Multiply by -1. Irrelevant.
%    Computes (0 % F). Now irrelevant.
'    Move the IP back again.
@    Terminate  the program.


# Japt, 64 3 bytes

¶Âa


Try it

## Explanation

Checks for strict equality (¶) between the input and the absolute value (a) of the input with bitwise NOT applied twice (Â).

• Does it work for numbers > 2^31 ? Nov 19, 2017 at 0:51

# Scala, 25 chars

(f:Double)=>f.ceil.abs==f

• Just to clarify, the type definition cannot be excluded Nov 22, 2017 at 16:58

# 05AB1E, 3 bytes

ïÄQ


Explanation:

ï      # Trim all decimals of the (implicit) input
Ä     # Take its absolute value
Q    # Check if it's equal to the (implicit) input (and output implicitly)


## Scratch in scratchblocks2, 92 67 bytes

thanks lirtosiast

when gf clicked


Try it online

• Surely when gf clicked ask[]and wait say<([abs v]of(answer))=(round(answer is shorter? Nov 19, 2018 at 9:24
• Ah yes, somehow I forgot about that. Nov 19, 2018 at 9:27

# PHP, 23+1 bytes

<?=$argn==abs(0|$argn);


prints 1 for truthy; empty output for falsy. Run as pipe with -F.

## Ruby, 18 characters

->x{x>=0&&0==x%1}


# Commodore BASIC (C64/128 C64Mini VIC-20...) 17 tokenized BASIC bytes

 0INPUTA:?A=INT(A)


In Commodore (Microsoft) 8-BIT BASIC, -1 is TRUE and 0 is FALSE.

If you require strictly 1 to represent TRUE and 0 to represent FALSE, this is how to do it:

### Version 2, 20 tokenized BASIC bytes

 0INPUTA:?ABS(A=INT(A))


or

 0INPUTA:?-(A=INT(A))


# Vyxal, 2 bytes

⌊=


Try it Online!

⌊  # Floor
= # Is equal to original?


# Thunno 2, 2 bytes

N=


Attempt This Online!

#### Explanation

N=  # Implicit input
N   # Cast to integer
=  # Equals the input?
# Implicit output


# JavaScript, 9 12 bytes

n=>!n%1&n>=0


Didn't realize that I had to take in negatives. Pointed out by @kamoroso94.

# Ruby, 20 bytes

->x{x.div(1)==x.abs}


# Ruby, 22 bytes

->x{[0,x].max==x.to_i}

• Why is there a leading space in the second code snippet?
– user72349
Nov 18, 2017 at 15:41

# Jq 1.5, 15 bytes

.>=0and.==floor


Not much to explain:

(. >= 0) and     # non-negative and
(. == floor)     # value == (value truncated to integer)


Try it online!

# Enlist, 4 bytes

:1Ae


Try it online!

Direct port of my Jelly answer above. Because of some reasons HyperNeutrino didn't implement Floor or Ceiling in Enlist, I use :1 (integer division by 1) instead, which takes 2 bytes.