Boolean data type

Uses your system voice; voice and rate in settings.

Snapshot

≈ 5 min read

Names in other languages

No names in other languages are held for this entry yet.

Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.

, the data type's namesake In computer science, the Boolean is a data type that has one of two possible values representing the two truth values of logic: true and false. 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 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).

, the data type's namesake]] In computer science, the Boolean is a data type that has one of two possible values representing the two truth values of logic: true and false. 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 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). Most programming languages, even those with no explicit Boolean type, have support for Boolean algebraic operations such as conjunction ( AND , & , * ), disjunction ( OR , | , + ), equivalence ( EQV , = , == ), exclusive or/non-equivalence ( XOR , NEQV , ^ , != , ¬ ), and negation ( NOT , ~ , ! , ¬ ). In some languages, like Ruby, Smalltalk, and Alice the true and false values belong to separate classes, e.g., True and False , 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 Nulls, 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 TRUE and FALSE though. Initial implementations of the language C (1972) provided no Boolean type, and to this day Boolean values are commonly represented by integers ( int s) in C programs. The comparison operators ( > , == , etc.) are defined to return a signed integer ( int ) result, either 0 (for false) or 1 (for true). Logical operators ( && , || , ! , etc.) and condition-testing statements ( if , while ) assume that zero (and hence a NULL pointer or a null string terminator '\0' also) is false and all other values are true. After enumerated types ( enum 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 (since C99) provides a Boolean type, called _Bool . Since C23, the Boolean is now a core data type called bool , with values true and false (previously these were provided by macros from the header stdbool.h , 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 bool 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 languages such as AWK. The D programming language has a proper Boolean data type bool . The bool 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 bool 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 bool means testing for 0 or for arithmetic types, and or for pointers or references. Objective-C also has a separate Boolean data type BOOL , with possible values being YES or NO , equivalents of true and false respectively. Also, in Objective-C compilers that support C99, C's _Bool type can be used, since Objective-C is a superset of C. The first version of FORTRAN (1957) and its successor FORTRAN II (1958) have no logical values or operations; even the conditional IF 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 ( LOGICAL ), truth literals ( .TRUE. and .FALSE. ), logical IF statement, Boolean-valued numeric comparison operators ( .EQ. , .GT. , etc.), and logical operators ( .AND. , .OR. , and .NOT. ). In FORMAT statements, a specific format descriptor (' L ') is provided for the parsing or formatting of logical values. A common extension prior to FORTRAN 77 was to extend the .EQ. and .NE. operators, or perhaps add a .XOR. operator for comparing Boolean expressions. Fortran 77 added .EQV. and .NEQV. operators to standardize the operations. Fortran 90 added alternative comparison operators , , == , /= , > , and >= . ==Truthy== ==See also== Boolean differential calculus Flag (programming) Shannon's expansion Three-valued logic True and false (commands) for shell scripting ==References==

Text derived from https://en.wikipedia.org/w/index.php?oldid=1376636571 under CC BY-SA 4.0; modifications have been made.