Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Programming Fundamentals/Floating-Point Data Type

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Overview A floating-point data type uses a common representation of real numbers as an approximation, which is essentially a trade-off between range and precision. For this reason, floating-point computation is often found in systems that include very small and very large real numbers, which require fast processing times. A number is, in general, represented approximately to a fixed number of significant digits and scaled using an exponent in some fixed base such as 10.Wikipedia: Floating-point arithmetic Discussion The floating-point data type is a family of data types that act alike and differ only in the size of their domains (the allowable values). The floating-point family of data types represents number values with fractional parts. They are technically stored as two integer values: a mantissa and an exponent. The floating-point family has the same attributes and acts or behaves similarly in all programming languages. They can always store negative or positive values thus they always are signed; unlike the integer data type that could be unsigned. The domain for floating-point data types varies because they could represent very large numbers or very small numbers. Rather than talk about the actual values, we mention the precision. The more bytes of storage the larger the mantissa and exponent, thus more precision. LanguageReserved WordSizePrecisionRangeC++float32 bits / 4 bytes7 decimal digits±3.40282347E+38C++double64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308C#float32 bits / 4 bytes7 decimal digits±3.40282347E+38C#double64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308Javafloat32 bits / 4 bytes7 decimal digits±3.40282347E+38Javadouble64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308JavaScriptNumber64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308Pythonfloat()64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308SwiftFloat32 bits / 4 bytes7 decimal digits±3.40282347E+38SwiftDouble64 bits / 8 bytes15 decimal digits±1.79769313486231570E+308 When converting operations with floating-point values, there may be more decimal places than you want. We can use the round function to limit the number of decimal places displayed. For example, round(1.12356,2) gives 1.12.Python.org: Built-in Functions Key Terms double The most often used floating-point family data type used. mantissa exponent The two integer parts of a floating-point value. precision The effect on the domain of floating-point values given a larger or smaller storage area in bytes. References cnx.org: Programming Fundamentals – A Modular Structured Approach using C++