This site is supported by donations to The OEIS Foundation.

Template:Ifinteger/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:Ifinteger. [<Edit> Template:Ifinteger]

[⧼Purge⧽ Template:Ifinteger/doc]

The {{ifint}}, {{ifinteger}} or {{if integer}} if-then-else function template returns {{{2|1}}} if {{{1|}}} is an integer, otherwise returns {{{3|0}}}.

The {{is integer}} predicate function template returns 1 (if true) or 0 (if false.)

Usage

{{ifint|input|output if true (optional, default: 1)|output if false (optional, default: 0)}}

or

{{ifinteger|input|output if true (optional, default: 1)|output if false (optional, default: 0)}}

or

{{if integer|input|output if true (optional, default: 1)|output if false (optional, default: 0)}}

or

{{is integer|input}}

Examples

Examples where an integer is recognized

Code Result Comment
{{is integer|0}} 1
{{is integer|-0}} 1
{{is integer|1}} 1
{{is integer|-34}} 1
{{if integer|1|an integer|not an integer}} an integer
{{if integer|+1000|an integer|not an integer}} an integer
{{if integer|10.0|an integer|not an integer}} an integer
{{if integer|10.00|an integer|not an integer}} an integer
{{ifinteger|99.98674e5|an integer|not an integer}} an integer
{{ifinteger|99.98674e6|an integer|not an integer}} an integer
{{ifinteger|99.98674e10|an integer|not an integer}} an integer
{{ifinteger|99.98674E10|an integer|not an integer}} an integer
{{ifinteger|-99.98674e+10|an integer|not an integer}} an integer
{{ifinteger|99.986746354298976E20|an integer|not an integer}} an integer
{{ifint|2^48|an integer|not an integer}} an integer
{{ifint|2^128|an integer|not an integer}} an integer
{{expr|1 / (2^1024 - 1)}} 0
{{ifint|1 / (2^1024 - 1)|an integer|not an integer}} an integer
{{expr|(2^1024 / 2^1024)^0}} 1
{{ifint|(2^1024 / 2^1024)^0|an integer|not an integer}} an integer
{{ifinteger|{{formatnum:999,999,999,999,999|R}}|yes|no}} yes
{{ifinteger|{{formatnum:999,999,999,999,999,999|R}}|yes|no}} yes

Examples where no integer is recognized

Code Result Comment
{{is integer}} 0
{{is integer|one}} 0
{{is integer|-0.1}} 0
{{is integer|0.897}} 0
{{is integer|1.523}} 0
{{is integer|-34.2}} 0
{{is integer|pi}} 0
{{ifinteger|99.98674e-10|an integer|not an integer}} not an integer
{{ifinteger|99.98674e2|an integer|not an integer}} not an integer
{{ifinteger|99.98674e4|an integer|not an integer}} not an integer
{{ifinteger|99 balloons|an integer|not an integer}} not an integer
{{ifinteger|one|an integer|not an integer}} not an integer
{{ifinteger|1,000.50|an integer|not an integer}} not an integer
{{ifinteger|1,000|an integer|not an integer}} not an integer
{{expr|2^1024 - 1}} INF (Cf. Maximum and minimum numbers allowed)
{{ifint|2^1024 - 1|an integer|not an integer}} an integer
{{expr|2^1024 - 2^1024}} NAN
{{ifint|2^1024 - 2^1024|an integer|not an integer}} not an integer (undefined)
{{expr|2^1024 / 2^1024}} NAN
{{ifint|2^1024 / 2^1024|an integer|not an integer}} not an integer (undefined)
{{expr|2^1024 + 2^1024 / 2^1024}} NAN
{{ifint|2^1024 + 2^1024 / 2^1024|an integer|not an integer}} not an integer (undefined)

Formatted numbers

This template requires unformatted numbers, it will not recognize formatted numbers, e.g. comma separated, which is by design since formatted numbers will break expression parsers. To remove the formatting from a number, you can wrap the number first in {{formatnum:number|R}}.[1]

code result
{{ifinteger|1,000.50|an integer|not an integer}} not an integer
{{ifinteger|{{formatnum:1,000.50|R}}|an integer|not an integer}} not an integer
{{ifinteger|1,000|an integer|not an integer}} not an integer
{{ifinteger|{{formatnum:1,000|R}}|an integer|not an integer}} an integer

Code

{{#iferror: {{#expr: {{{1|NAN}}} }}
| {{{3|0}}}
| {{#ifexpr: floor ( {{{1}}} ) = ( {{{1}}} )
  | {{{2|1}}}
  | {{{3|0}}}
  }}
}}

See also

Notes