This site is supported by donations to The OEIS Foundation.
Template:Bool/doc
From OeisWiki
The {{Bool}} (Boolean) logical function template returns the Boolean value 1 or 0 according to whether the input expression evaluates to a number being nonzero or zero respectively, or whether the input expression evaluates to a nonempty string or either a null or empty (only spaces, tabs or newlines) string respectively.
Contents
Usage
To use it, enter
- {{Bool|input expression}}
or
- {{Bool}}
which returns 1 if input expression evaluates to
- a number being nonzero,
- a nonempty string,
and returns 0 if input expression evaluates to
- a number being zero,
- a null or empty (only spaces, tabs or newlines) string.
Valid input
Examples with valid input
Code Result Comment {{Bool|1}} 1 {{Bool|-1}} 1 {{Bool|3.5}} 1 {{Bool|-5}} 1 {{Bool|pi}} 1 {{Bool|5-(3+2)}} 0 {{Bool|5-(3+1)}} 1 {{Bool|0}} 0 {{Bool|blob}} 1 {{Bool|6 blobs}} 1 {{Bool|yes}} 1 (use template {{truth}} for a preassigned truth/Boolean value interpretation) {{Bool|no}} 1 (use template {{truth}} for a preassigned truth/Boolean value interpretation) {{Bool|true}} 1 (use template {{truth}} for a preassigned truth/Boolean value interpretation) {{Bool|false}} 1 (use template {{truth}} for a preassigned truth/Boolean value interpretation) {{Bool| {{truth|yes|Bool}} }} 1 {{Bool| {{truth|no|Bool}} }} 0 {{Bool| {{truth|true|Bool}} }} 1 {{Bool| {{truth|false|Bool}} }} 0 {{Bool}} 0 (null input) {{Bool|}} 0 (empty string as input) {{Bool| }} 0 (space as input) {{Bool| }} 0 (newline as input)
Code
{{#if: {{{1|}}} | {{ifnum| {{{1}}} | {{#ifexpr: ({{{1}}}) = 0 | 0 | 1 }} | 1<!-- nonempty string --> }} | 0<!-- null or blank (only spaces, tabs or newlines) input --> }}
See also
- {{truth}} (for a preassigned truth/Boolean value TRUE/1 or FALSE/0 interpretation of true/false, yes/no, on/off, good/bad, right/wrong)