Long double
Encyclopedia
In C
and related programming language
s,
data type
that is often more precise than double precision
. As with C's other floating point types, it may not necessarily map to an IEEE format
.
, which extended the standard library
to include functions operating on
, most compilers implement
extended precision
type supported by that hardware (sometimes stored as 12 or 16 bytes to maintain data structure alignment
). An exception is Microsoft Visual C++ for x86, which makes
on Microsoft Windows supports extended precision, but requires the
Compilers may also use
and SPARCv9
machines,
. Otherwise,
With the GNU C Compiler,
) or 128-bit quadruple precision (e.g. on SPARC
). As of gcc 4.3, a quadruple precision is also supported on x86, but as the nonstandard type
Although the x86 architecture, and specifically the x87
floating-point instructions on x86, supports 80-bit extended-precision operations, it is possible to configure the processor to automatically round operations to double (or even single) precision. With gcc on several BSD operating systems (FreeBSD
, NetBSD
, and OpenBSD
), double-precision mode is the default, and
(from specification of 3.0, which uses "ANSI/IEEE Standard 754-1985" as its reference), "the long double data type represents an IEEE double-extended floating-point number, which has an exponent of at least 15 bits in length and a signed fraction of at least 64 bits", with GIOP/IIOP CDR, whose floating-point types "exactly follow the IEEE standard formats for floating point numbers", marshalling this as what seems to be IEEE 754-2008 binary128 a.k.a. quadruple precision without using that name.
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
and related programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
s,
long double
refers to a floating pointFloating point
In computing, floating point describes a method of representing real numbers in a way that can support a wide range of values. Numbers are, in general, represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16...
data type
Data type
In computer programming, a data type is a classification identifying one of various types of data, such as floating-point, integer, or Boolean, that determines the possible values for that type; the operations that can be done on values of that type; the meaning of the data; and the way values of...
that is often more precise than double precision
Double precision
In computing, double precision is a computer number format that occupies two adjacent storage locations in computer memory. A double-precision number, sometimes simply called a double, may be defined to be an integer, fixed point, or floating point .Modern computers with 32-bit storage locations...
. As with C's other floating point types, it may not necessarily map to an IEEE format
IEEE floating-point standard
IEEE 754–1985 was an industry standard for representingfloating-pointnumbers in computers, officially adopted in 1985 and superseded in 2008 byIEEE 754-2008. During its 23 years, it was the most widely used format for...
.
History
Thelong double
type was present in the original 1989 C standard but support was improved by the 1999 revision of the C standard, or C99C99
C99 is a modern dialect of the C programming language. It extends the previous version with new linguistic and library features, and helps implementations make better use of available computer hardware and compiler technology.-History:...
, which extended the standard library
Library (computer science)
In computer science, a library is a collection of resources used to develop software. These may include pre-written code and subroutines, classes, values or type specifications....
to include functions operating on
long double
such as sinl
and strtold
.Implementations
On the x86 architectureX86 architecture
The term x86 refers to a family of instruction set architectures based on the Intel 8086 CPU. The 8086 was launched in 1978 as a fully 16-bit extension of Intel's 8-bit based 8080 microprocessor and also introduced segmentation to overcome the 16-bit addressing barrier of such designs...
, most compilers implement
long double
as the 80-bitBit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...
extended precision
Extended precision
The term extended precision refers to storage formats for floating point numbers not falling into the regular sequence of single, double, and quadruple precision formats...
type supported by that hardware (sometimes stored as 12 or 16 bytes to maintain data structure alignment
Data structure alignment
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. When a modern computer reads from or writes to a memory address, it will do this in word sized chunks...
). An exception is Microsoft Visual C++ for x86, which makes
long double
a synonym for double
. The Intel C++ compilerIntel C++ Compiler
Intel C++ Compiler is a group of C and C++ compilers from Intel Corporation available for GNU/Linux, Mac OS X, and Microsoft Windows....
on Microsoft Windows supports extended precision, but requires the
/Qlong‑double
switch to access the hardware's extended precision format.Compilers may also use
long double
for a 128-bit quadruple precision format, which is currently implemented in software. On some PowerPCPowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...
and SPARCv9
SPARC
SPARC is a RISC instruction set architecture developed by Sun Microsystems and introduced in mid-1987....
machines,
long double
is implemented as a double-double arithmetic, where a long double
value is regarded as the exact sum of two double-precision values, giving at least a 106-bit precision; with such a format, the long double
type does not conform to the IEEE floating-point standardIEEE floating-point standard
IEEE 754–1985 was an industry standard for representingfloating-pointnumbers in computers, officially adopted in 1985 and superseded in 2008 byIEEE 754-2008. During its 23 years, it was the most widely used format for...
. Otherwise,
long double
is simply a synonym for double
(double precision).With the GNU C Compiler,
long double
is 80-bit extended precision on x86 processors regardless of the physical storage used for the type (which can be either 96 or 128 bits), On some other architectures, long double
can be double-double (e.g. on PowerPCPowerPC
PowerPC is a RISC architecture created by the 1991 Apple–IBM–Motorola alliance, known as AIM...
) or 128-bit quadruple precision (e.g. on SPARC
SPARC
SPARC is a RISC instruction set architecture developed by Sun Microsystems and introduced in mid-1987....
). As of gcc 4.3, a quadruple precision is also supported on x86, but as the nonstandard type
__float128
rather than long double
.Although the x86 architecture, and specifically the x87
X87
x87 is a floating point-related subset of the x86 architecture instruction set. It originated as an extension of the 8086 instruction set in the form of optional floating point coprocessors that worked in tandem with corresponding x86 CPUs. These microchips had names ending in "87"...
floating-point instructions on x86, supports 80-bit extended-precision operations, it is possible to configure the processor to automatically round operations to double (or even single) precision. With gcc on several BSD operating systems (FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
, NetBSD
NetBSD
NetBSD is a freely available open source version of the Berkeley Software Distribution Unix operating system. It was the second open source BSD descendant to be formally released, after 386BSD, and continues to be actively developed. The NetBSD project is primarily focused on high quality design,...
, and OpenBSD
OpenBSD
OpenBSD is a Unix-like computer operating system descended from Berkeley Software Distribution , a Unix derivative developed at the University of California, Berkeley. It was forked from NetBSD by project leader Theo de Raadt in late 1995...
), double-precision mode is the default, and
long double
operations are effectively reduced to double precision. However, it is possible to override this within an individual program via the FLDCW "floating-point load control-word" instruction. Microsoft Windows with Visual C++ also sets the processor in double-precision mode by default, but this can again be overridden within an individual program (e.g. by the _controlfp_s
function in Visual C++). The Intel C++ Compiler for x86, on the other hand, enables extended-precision mode by default.Other specifications
In CORBAÇorba
Chorba , ciorbă , shurpa , shorpo , or sorpa is one of various kinds of soup or stew found in national cuisines across Middle East...
(from specification of 3.0, which uses "ANSI/IEEE Standard 754-1985" as its reference), "the long double data type represents an IEEE double-extended floating-point number, which has an exponent of at least 15 bits in length and a signed fraction of at least 64 bits", with GIOP/IIOP CDR, whose floating-point types "exactly follow the IEEE standard formats for floating point numbers", marshalling this as what seems to be IEEE 754-2008 binary128 a.k.a. quadruple precision without using that name.