Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Boolean data type
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Data having only values "true" or "false"}} [[File:George_Boole_color.jpg|thumb|George Boole]] In [[computer science]], the '''Boolean''' (sometimes shortened to Bool) is a [[data type]] that has one of two possible values (usually denoted ''true'' and ''false'') which is intended to represent the two [[truth value]]s of [[logic]] and [[Boolean algebra]]. It is named after [[George Boole]], who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is primarily associated with [[Conditional (computer programming)|conditional]] statements, which allow different actions by changing [[control flow]] depending on whether a programmer-specified Boolean ''condition'' evaluates to true or false. It is a special case of a more general ''logical data type—''logic does not always need to be Boolean (see [[probabilistic logic]]). == Generalities == In [[programming language]]s with a built-in Boolean data type, such as [[Pascal (programming language)|Pascal]], [[C (programming language)|C]], [[Python (programming language)|Python]] or [[Java (programming language)|Java]], the [[comparison operator]]s such as <code>></code> and <code>≠</code> are usually defined to return a Boolean value. [[if-then-else|Conditional]] and [[while loop|iterative]] commands may be defined to test Boolean-valued expressions. Languages with no explicit Boolean data type, like [[ANSI C#C90|C90]] and [[Lisp (programming language)|Lisp]], may still represent truth values by some other data type. [[Common Lisp]] uses an empty [[List (computing)|list]] for false, and any other value for true. The C programming language uses an [[Integer (computer science)|integer]] type, where relational expressions like <code>i > j</code> and logical expressions connected by <code>&&</code> and <code>||</code> are defined to have value 1 if true and 0 if false, whereas the test parts of <code>if</code>, <code>while</code>, <code>for</code>, etc., treat any non-zero value as true.<ref name="k&r1e">{{cite book |first1= Brian W |last1= Kernighan |author-link1= Brian Kernighan |first2= Dennis M |last2= Ritchie |author-link2= Dennis Ritchie |page= [https://archive.org/details/cprogramminglang00kern/page/41 41] |title= [[The C Programming Language]] |edition= 1st |publisher= [[Prentice Hall]] |year= 1978 |location= [[Englewood Cliffs, NJ]] |isbn= 0-13-110163-3 }}</ref><ref>{{cite book |pages= [https://archive.org/details/ansiisostandardc00plau/page/86 86–93] |first1= PJ |last1= Plauger |author-link1= P. J. Plauger |first2= Jim |last2= Brodie |title= ANSI and ISO Standard C Programmer's reference |publisher= [[Microsoft Press]] |orig-year= 1989 |year= 1992 |isbn= 1-55615-359-7 |url= https://archive.org/details/ansiisostandardc00plau/page/86 }}</ref> Indeed, a Boolean variable may be regarded (and implemented) as a numerical variable with one binary digit ([[bit]]), or as a bit string of length one, which can store only two values. The implementation of Booleans in computers are most likely represented as a full [[Word (computer architecture)|word]], rather than a bit; this is usually due to the ways computers transfer blocks of information. Most programming languages, even those with no explicit Boolean type, have support for Boolean algebraic operations such as [[Logical conjunction|conjunction]] (<code>AND</code>, <code>&</code>, <code>*</code>), [[disjunction]] (<code>OR</code>, <code>|</code>, <code>+</code>), [[Logical equivalence|equivalence]] (<code>EQV</code>, <code>=</code>, <code>==</code>), [[exclusive or]]/non-equivalence (<code>XOR</code>, <code>NEQV</code>, <code>^</code>, <code>!=</code>, <code>¬</code>), and [[negation]] (<code>NOT</code>, <code>~</code>, <code>!</code>, <code>¬</code>). In some languages, like [[Ruby (programming language)|Ruby]], [[Smalltalk]], and [[Alice (software)|Alice]] the ''true'' and ''false'' values belong to separate [[Class (computer programming)|classes]], e.g., <code>True</code> and <code>False</code>, respectively, so there is no one Boolean ''type''. In [[SQL]], which uses a [[three-valued logic]] for explicit comparisons because of its special treatment of [[Null (SQL)|Null]]s, the Boolean data type (introduced in [[SQL:1999]]) is also defined to include more than two truth values, so that SQL ''Booleans'' can store all logical values resulting from the evaluation of predicates in SQL. A column of Boolean type can be restricted to just <code>TRUE</code> and <code>FALSE</code> though. == Language-specific implementations == === ALGOL and the built-in BOOLEAN type === One of the earliest programming languages to provide an explicit <code>BOOLEAN</code> data type is [[ALGOL 60]] (1960) with values ''true'' and ''false'' and logical operators denoted by symbols '<math>\wedge</math>' (and), '<math>\vee</math>' (or), '<math>\supset</math>' (implies), '<math>\equiv</math>' (equivalence), and '<math>\neg</math>' (not). Due to input device and [[character set]] limits on many computers of the time, however, most compilers used alternative representations for many of the operators, such as <code>AND</code> or <code>'AND'</code>. This approach with <code>BOOLEAN</code> as a built-in (either [[Primitive data type|primitive]] or otherwise predefined) [[data type]] was adopted by many later programming languages, such as [[Simula]] 67 (1967), [[ALGOL 68]] (1970),<ref>{{cite web |url=http://www.fh-jena.de/~kleine/history/languages/Algol68-Report.pdf |title=Report on the Algorithmic Language ALGOL 68, Section 10.2.2. |date=August 1968 |access-date=30 April 2007 |url-status=live |archive-url=https://web.archive.org/web/20080406061108/http://www.fh-jena.de/~kleine/history/languages/Algol68-Report.pdf |archive-date=6 April 2008 }}</ref> [[Pascal (programming language)|Pascal]] (1970), [[Ada (programming language)|Ada]] (1980), [[Java (programming language)|Java]] (1995), and [[C Sharp (programming language)|C#]] (2000), among others. === C, C++, D, Objective-C, AWK === Initial implementations of the language [[C (programming language)|C]] (1972) provided no Boolean type, and to this day Boolean values are commonly represented by integers (<code>int</code>s) in C programs. The comparison operators (<code>></code>, <code>==</code>, etc.) are defined to return a signed integer (<code>int</code>) result, either 0 (for false) or 1 (for true). Logical operators (<code>&&</code>, <code>||</code>, <code>!</code>, etc.) and condition-testing statements (<code>if</code>, <code>while</code>) assume that zero (and hence a [[NULL pointer]] or a [[Null character|null string terminator]] '\0' also) is false and all other values are true. After [[enumerated type]]s (<code>enum</code>s) were added to the [[American National Standards Institute]] version of C, [[ANSI C]] (1989), many C programmers got used to defining their own Boolean types as such, for readability reasons. However, enumerated types are equivalent to integers according to the language standards; so the effective identity between Booleans and integers is still valid for C programs. Standard [[C (programming language)|C]] (since [[C99]]) provides a Boolean type, called <code>_Bool</code>. Since [[C23 (C standard revision)|C23]], the Boolean is now a core data type called <code>bool</code>, with values <code>true</code> and <code>false</code> (previously these was provided by macros from the header [[C data types#stdbool.h|<code>stdbool.h</code>]], which is now obsolete). The language guarantees that any two true values will compare equal (which was impossible to achieve before the introduction of the type). Boolean values still behave as integers, can be stored in integer variables, and used anywhere integers would be valid, including in indexing, arithmetic, parsing, and formatting. This approach (''Boolean values are just integers'') has been retained in all later versions of C. Note, that this does not mean that any integer value can be stored in a Boolean variable. [[C++]] has had the Boolean data type <code>bool</code> since [[C++98]], but with automatic conversions from scalar and pointer values that are very similar to those of C. This approach was adopted also by many later languages, especially by some [[scripting language]]s such as [[AWK]]. The [[D programming language]] has a proper Boolean data type <code>bool</code>. The <code>bool</code> type is a byte-sized type that can only hold the value true or false. The only operators that can accept operands of type bool are: &, |, ^, &=, |=, ^=, !, &&, || and ?:. A <code>bool</code> value can be implicitly converted to any integral type, with false becoming 0 and true becoming 1. The numeric literals 0 and 1 can be implicitly converted to the bool values false and true, respectively. Casting an expression to <code>bool</code> means testing for 0 or !=0 for arithmetic types, and null or !=null for pointers or references. [[Objective-C]] also has a separate Boolean data type <code>BOOL</code>, with possible values being <code>YES</code> or <code>NO</code>, equivalents of true and false respectively.<ref>{{cite web|url=https://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html|title=Guides and Sample Code|website=developer.apple.com|access-date=1 May 2018|url-status=live|archive-url=https://web.archive.org/web/20110907013839/http://developer.apple.com/library/iOS/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/FoundationTypesandCollections/FoundationTypesandCollections.html|archive-date=7 September 2011}}</ref> Also, in Objective-C compilers that support C99, C's <code>_Bool</code> type can be used, since Objective-C is a [[superset]] of C. === Forth === [[Forth (programming language)]] has no Boolean type, it uses regular integers: value 0 (all bits low) represents false, and -1 (all bits high) represents true. This allows the language to define only one set of logical operators, instead of one for mathematical calculations and one for conditions.<ref>{{Cite web|date=2022-02-11|title=4. Decisions, Decisions...|url=https://www.forth.com/starting-forth/4-conditional-if-then-statements/|access-date=2022-02-11|website=Forth Inc.|language=en-US}}</ref> === Fortran === The first version of [[FORTRAN]] (1957) and its successor FORTRAN II (1958) have no logical values or operations; even the conditional <code>IF</code> statement takes an arithmetic expression and branches to one of three locations according to its sign; see [[arithmetic IF]]. FORTRAN IV (1962), however, follows the ALGOL 60 example by providing a Boolean data type (<code>LOGICAL</code>), truth literals (<code>.TRUE.</code> and <code>.FALSE.</code>), logical <code>IF</code> statement, Boolean-valued numeric comparison operators (<code>.EQ.</code>, <code>.GT.</code>, etc.), and logical operators (<code>.NOT.</code>, <code>.AND.</code>, <code>.OR.</code>, <code>.EQV.</code>, and <code>.NEQV.</code>). In <code>FORMAT</code> statements, a specific format descriptor ('<code>L</code>') is provided for the parsing or formatting of logical values.<ref>Digital Equipment Corporation, ''DECSystem10 FORTRAN IV Programmers Reference Manual''. Reprinted in ''Mathematical Languages Handbook''. [http://www.bitsavers.org/pdf/tymshare/tymcom-x/Tymcom-X_Reference_Series_Fortran_IV_Jan73.pdf Online version] {{webarchive|url=https://web.archive.org/web/20110814003524/http://www.bitsavers.org/pdf/tymshare/tymcom-x/Tymcom-X_Reference_Series_Fortran_IV_Jan73.pdf |date=2011-08-14 }} accessed 2011-11-16.</ref><!-- Fortrans IV and 66 lack XOR and EQV. --> Fortran 90 added alternative comparison operators <code><</code>, <code><=</code>, <code>==</code>, <code>/=</code>, <code>></code>, and <code>>=</code>. === Java === In [[Java (programming language)|Java]], the value of the <code>boolean</code> data type can only be either <code>true</code> or <code>false</code>.<ref name="W3Schools Online Web Tutorials">{{cite web | title=Java Booleans | website=W3Schools Online Web Tutorials | url=https://www.w3schools.com/java/java_booleans.asp | access-date=2021-02-17}}</ref> === Lisp and Scheme === The language [[Lisp (programming language)|Lisp]] (1958) never had a built-in Boolean data type. Instead, conditional constructs like <code>cond</code> assume that the logical value ''false'' is represented by the empty list <code>()</code>, which is defined to be the same as the special atom <code>nil</code> or <code>NIL</code>; whereas any other [[s-expression]] is interpreted as ''true''. For convenience, most modern dialects of Lisp predefine the atom <code>t</code> to have value <code>t</code>, so that <code>t</code> can be used as a mnemonic notation for ''true''. This approach (''any value can be used as a Boolean value'') was retained in most Lisp dialects ([[Common Lisp]], [[Scheme (programming language)|Scheme]], [[Emacs Lisp]]), and similar models were adopted by many [[scripting language]]s, even ones having a distinct Boolean type or Boolean values; although which values are interpreted as ''false'' and which are ''true'' vary from language to language. In Scheme, for example, the ''false'' value is an atom distinct from the empty list, so the latter is interpreted as ''true''. Common Lisp, on the other hand, also provides the dedicated <code>boolean</code> type, derived as a specialization of the symbol.<ref>{{Cite web|url=http://www.lispworks.com/documentation/lw50/CLHS/Body/t_ban.htm|title = CLHS: Type BOOLEAN}}</ref> === Pascal, Ada, and Haskell === The language [[Pascal (programming language)|Pascal]] (1970) popularized the concept of programmer-defined enumerated types, previously available with different nomenclature in [[COBOL]], [[FACT (computer language)|FACT]] and [[JOVIAL]]. A built-in <code>Boolean</code> data type was then provided as a predefined enumerated type with values <code>FALSE</code> and <code>TRUE</code>. By definition, all comparisons, logical operations, and conditional statements applied to and/or yielded <code>Boolean</code> values. Otherwise, the <code>Boolean</code> type had all the facilities which were available for enumerated types in general, such as ordering and use as indices. In contrast, converting between <code>Boolean</code>s and integers (or any other types) still required explicit tests or function calls, as in ALGOL 60. This approach (''Boolean is an enumerated type'') was adopted by most later languages which had enumerated types, such as [[Modula]], [[Ada (programming language)|Ada]], and [[Haskell]]. === Perl and Lua === [[Perl]] has no Boolean data type. Instead, any value can behave as Boolean in Boolean context (condition of <code>if</code> or <code>while</code> statement, argument of <code>&&</code> or <code>||</code>, etc.). The number <code>0</code>, the [[String (computer science)|strings]] <code>"0"</code> and <code>""</code>, the empty list <code>()</code>, and the special value <code>undef</code> evaluate to false.<ref>{{cite web |url=http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood |title=perlsyn - Perl Syntax / Truth and Falsehood |access-date=10 September 2013 |url-status=live |archive-url=https://web.archive.org/web/20130826100652/http://perldoc.perl.org/perlsyn.html#Truth-and-Falsehood |archive-date=26 August 2013 }}</ref> All else evaluates to true. [[Lua (programming language)|Lua]] has a Boolean data type, but non-Boolean values can also behave as Booleans. The non-value <code>nil</code> evaluates to false, whereas every other data type value evaluates to true. This includes the empty string <code>""</code> and the number <code>0</code>, which are very often considered <code>false</code> in other languages. === PL/I === [[PL/I]] has no Boolean data type. Instead, comparison operators generate BIT(1) values; '0'B represents '''false''' and '1'B represents '''true'''. The operands of, e.g., <code>&</CODE>, <code>|</CODE>, <code>¬</CODE>, are converted to bit strings and the operations are performed on each bit. The ''element-expression'' of an <CODE>IF</CODE> statement is true if any bit is 1. === Python and Ruby === {{further|Truthy (computing)}} [[Python (programming language)|Python]], from version 2.3 forward, has a <code>bool</code> type which is a [[Subclass (computer science)|subclass]] of <code>int</code>, the standard integer type.<ref>{{cite web |last= van Rossum |first= Guido |author-link= Guido van Rossum |title= PEP 285 -- Adding a bool type |date= 3 April 2002 |url= https://www.python.org/dev/peps/pep-0285/ |access-date= 15 May 2013 |url-status= live |archive-url= https://web.archive.org/web/20130501225326/http://www.python.org/dev/peps/pep-0285/ |archive-date= 1 May 2013 }}</ref> It has two possible values: <code>True</code> and <code>False</code>, which are ''special versions'' of 1 and 0 respectively and behave as such in arithmetic contexts. Also, a numeric value of zero (integer or fractional), the null value (<code>None</code>), the empty string, and empty containers (lists, [[Set (computing)|sets]], etc.) are considered Boolean false; all other values are considered Boolean true by default.<ref>{{cite web |url= https://docs.python.org/3.3/reference/expressions.html |title= Expressions |website= Python v3.3.2 documentation |access-date= 15 May 2013 |url-status= live |archive-url= https://web.archive.org/web/20130522082703/http://docs.python.org/3.3/reference/expressions.html |archive-date= 22 May 2013 }}</ref> Classes can define how their instances are treated in a Boolean context through the special method <code>__nonzero__</code> (Python 2) or <code>__bool__</code> (Python 3). For containers, <code>__len__</code> (the special method for determining the length of containers) is used if the explicit Boolean conversion method is not defined. In [[Ruby (programming language)|Ruby]], in contrast, only <code>nil</code> (Ruby's null value) and a special <code>false</code> object are ''false''; all else (including the integer 0 and empty arrays) is ''true''. === Rexx === [[Rexx]] has no Boolean data type. Instead, comparison operators generate 0 or 1; 0 represents '''false''' and 1 represents '''true'''. The operands of, e.g., <code>&</CODE>, <code>|</CODE>, <code>¬</CODE>, must be 0 or 1. === SQL === {{main|Null (SQL)#Comparisons with NULL and the three-valued logic (3VL)}} Booleans appear in SQL when a [[Condition (SQL)|condition]] is needed, such as {{mono|WHERE}} clause, in form of predicate which is produced by using operators such as comparison operators, {{mono|IN}} operator, {{mono|IS (NOT) NULL}} etc. However, apart from {{mono|TRUE}} and {{mono|FALSE}}, these operators can also yield a third state, called {{mono|UNKNOWN}}, when comparison with [[Null (SQL)|{{NULL}}]] is made. The SQL92 standard introduced {{mono|IS (NOT) TRUE, IS (NOT) FALSE,}} and {{mono|IS (NOT) UNKNOWN}} operators which evaluate a predicate, which predated the introduction of Boolean type in [[SQL:1999]]. The SQL:1999 standard introduced a {{mono|BOOLEAN}} data type as an optional feature (T031). When restricted by a {{mono|1=NOT NULL}} constraint, a SQL {{mono|BOOLEAN}} behaves like Booleans in other languages, which can store only {{mono|TRUE}} and {{mono|FALSE}} values. However, if it is nullable, which is the default like all other SQL data types, it can have the special null value also. Although the SQL standard defines three [[Literal (computer programming)|literals]] for the {{mono|BOOLEAN}} type – {{mono|TRUE, FALSE,}} and {{mono|UNKNOWN}} {{--}} it also says that the {{mono|NULL BOOLEAN}} and {{mono|UNKNOWN}} "may be used interchangeably to mean exactly the same thing".<ref name="Date2011">{{cite book|author=C. Date|title=SQL and Relational Theory: How to Write Accurate SQL Code|url=https://books.google.com/books?id=Ew06OZtjuJEC&pg=PA83|year=2011|publisher=O'Reilly Media, Inc.|isbn=978-1-4493-1640-2|page=83}}</ref><ref>ISO/IEC 9075-2:2011 §4.5</ref> This has caused some controversy because the identification subjects {{mono|UNKNOWN}} to the equality comparison rules for NULL. More precisely {{code|UNKNOWN {{=}} UNKNOWN}} is not {{mono|TRUE}} but {{mono|UNKNOWN/NULL}}.<ref name="Prigmore2007">{{cite book|author=Martyn Prigmore|title=Introduction to Databases With Web Applications|url=https://books.google.com/books?id=PKggKqIZnN0C&pg=PA197|year=2007|publisher=Pearson Education Canada|isbn=978-0-321-26359-9|page=197}}</ref> As of 2012 few major SQL systems implement the T031 feature.<ref>Troels Arvin, [http://troels.arvin.dk/db/rdbms/#data_types-boolean Survey of BOOLEAN data type implementation] {{webarchive|url=https://web.archive.org/web/20050309010315/http://troels.arvin.dk/db/rdbms/ |date=2005-03-09 }}</ref> Firebird and [[PostgreSQL]] are notable exceptions, although PostgreSQL implements no {{mono|UNKNOWN}} literal; {{NULL}} can be used instead.<ref>{{cite web|url=http://www.postgresql.org/docs/current/static/datatype-boolean.html|title=PostgreSQL: Documentation: 10: 8.6. Boolean Type|website=www.postgresql.org|access-date=1 May 2018|url-status=live|archive-url=https://web.archive.org/web/20180309053449/https://www.postgresql.org/docs/current/static/datatype-boolean.html|archive-date=9 March 2018}}</ref> The treatment of Boolean values differs between SQL systems. For example, in [[Microsoft SQL Server]], Boolean value is not supported at all, neither as a standalone data type nor representable as an integer. It shows the error message "An expression of non-Boolean type specified in a context where a condition is expected" if a column is directly used in the {{mono|WHERE}} clause, e.g. {{code|1=SELECT a FROM t WHERE a|2=tsql}}, while a statement such as {{code|1=SELECT column IS NOT NULL FROM t|2=tsql}} yields a syntax error. The {{mono|BIT}} data type, which can only store integers 0 and 1 apart from {{mono|NULL}}, is commonly used as a workaround to store Boolean values, but workarounds need to be used such as {{code|1=UPDATE t SET flag = IIF(col IS NOT NULL, 1, 0) WHERE flag = 0|2=tsql}} to convert between the integer and Boolean expression. [[Microsoft Access]], which uses the [[Access Database Engine]] (ACE/JET),<ref>{{Cite web|title=Migrate an Access database to SQL Server|url=https://support.microsoft.com/en-us/office/migrate-an-access-database-to-sql-server-7bac0438-498a-4f53-b17b-cc22fc42c979|access-date=2020-10-19|website=support.microsoft.com|language=en-US}}</ref> also does not have a Boolean data type. Similar to MS SQL Server, it uses a {{mono|BIT}} data type.<ref>{{Cite web|last=o365devx|title=SQL data types (Access desktop database reference)|url=https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/sql-data-types|access-date=2020-10-19|website=docs.microsoft.com|language=en-us}}</ref> In Access it is known as a Yes/No data type<ref>{{Cite web|title=Introduction to data types and field properties|url=https://support.microsoft.com/en-us/office/introduction-to-data-types-and-field-properties-30ad644f-946c-442e-8bd2-be067361987c|access-date=2020-10-19|website=support.microsoft.com|language=en-US}}</ref> which can have two values; Yes (True) or No (False). The BIT data type in Access can also be represented numerically: True is −1 and False is 0.<ref>{{Cite web|title=Boolean Data - MS-Access Tutorial|url=https://sourcedaddy.com/ms-access/boolean-data.html|access-date=2020-10-19|website=sourcedaddy.com}}</ref> This differs from MS SQL Server in two ways, even though both are Microsoft products: # Access represents {{mono|TRUE}} as −1, while it is 1 in SQL Server # Access does not support the Null tri-state, supported by SQL Server [[PostgreSQL]] has a distinct {{mono|BOOLEAN}} type as in the standard,<ref>{{Cite web|url=https://www.postgresql.org/docs/9.1/datatype-boolean.html|title = Boolean Type|date = 27 October 2016}}</ref> which allows predicates to be stored directly into a {{mono|BOOLEAN}} column, and allows using a {{mono|BOOLEAN}} column directly as a predicate in a {{mono|WHERE}} clause. In [[MySQL]], {{mono|BOOLEAN}} is treated as an alias of {{code|TINYINT(1)|mysql}};<ref>{{cite web |url=https://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html |title=MySQL :: MySQL 8.0 Reference Manual :: 12.1.1 Numeric Type Overview |website=dev.mysql.com |url-status=dead |archive-url=https://web.archive.org/web/20160922212232/http://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html |archive-date=2016-09-22}} </ref> {{mono|TRUE}} is the same as integer 1 and {{mono|FALSE}} is the same as integer 0.<ref>{{Cite web|url=https://dev.mysql.com/doc/refman/8.0/en/boolean-literals.html|title=MySQL :: MySQL 8.0 Reference Manual :: 9.1.6 Boolean Literals|website=dev.mysql.com}}</ref> Any non-zero integer is true in conditions. === Tableau === [[Tableau Software]] has a BOOLEAN data type.<ref>{{Cite web|title=Data Types|url=https://help.tableau.com/current/pro/desktop/en-us/datafields_typesandroles_datatypes.htm|access-date=2020-10-19|website=help.tableau.com|language=en-us}}</ref> The literal of a Boolean value is <code>True</code> or <code>False</code>.<ref>{{Cite web|title=Formatting Calculations in Tableau|url=https://help.tableau.com/current/pro/desktop/en-us/functions_operators.htm#literal-expression-syntax|access-date=2020-10-19|website=help.tableau.com|language=en-us}}</ref> The Tableau <code>INT()</code> function converts a Boolean to a number, returning 1 for True and 0 for False.<ref>{{Cite web|date=2020-09-11|title=Boolean makes Tableau faster - true or false?|url=https://tarsolutions.co.uk/blog/tableau-boolean-data-type/|access-date=2020-10-19|website=TAR Solutions|language=en-US}}</ref> === Tcl === [[Tcl]] has no separate Boolean type. Like in C, the integers 0 (false) and 1 (true—in fact any nonzero integer) are used.<ref> {{cite web |title= PEP 285 -- Adding a bool type |date= 4 May 2011 |url= https://wiki.tcl.tk/16235 |access-date= 28 March 2018 |url-status= live |archive-url= https://web.archive.org/web/20180328231245/https://wiki.tcl.tk/16235 |archive-date= 28 March 2018 }}</ref> Examples of coding: {{sxhl|2=tcl| set v 1 if { $v } { puts "V is 1 or true" } }} The above will show {{samp|V is 1 or true}} since the expression evaluates to 1. {{sxhl|2=tcl| set v "" if { $v } .... }} The above will render an error, as variable {{mono|v}} cannot be evaluated as 0 or 1. ==Truthy== {{excerpt|Truth value#Computing}} ==See also== * [[Boolean differential calculus]] * [[Flag (programming)]] * [[Shannon's expansion]] * [[Three-valued logic]] * [[True and false (commands)]] for [[shell scripting]] ==References== {{Reflist|2}} {{Data types}} [[Category:Boolean algebra]] [[Category:Data types]] [[Category:Primitive types]] [[Category:Articles with example ALGOL 68 code]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:--
(
edit
)
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Code
(
edit
)
Template:Data types
(
edit
)
Template:Excerpt
(
edit
)
Template:Further
(
edit
)
Template:Main
(
edit
)
Template:Mono
(
edit
)
Template:NULL
(
edit
)
Template:Reflist
(
edit
)
Template:Samp
(
edit
)
Template:Short description
(
edit
)
Template:Sxhl
(
edit
)
Template:Webarchive
(
edit
)