Table of Contents
CPP double keyword
Return to double, C++ Reserved words, C++, Reserved Words, CPP Glossary, CPP Topics
In the context of programming languages, the term “double” typically refers to a data type used for storing double-precision floating-point numbers, which are real numbers that can contain fractions and can be very large or very small. The specifics of how this is implemented can vary significantly from one language to another. Below is a comparison of the `double` keyword or its equivalent in various programming languages, including code examples and references to official documentation.
- C++
In C++, `double` is a primitive data type used to store double-precision floating-point numbers. It provides a significant amount of precision for representing real numbers. A `double` in C++ typically has a precision of about 15 decimal digits and occupies 8 bytes in memory.
```cpp double myNumber = 3.14; ```
Official Documentation: s://en.cppreference.com/w/cpp/language/types(https://en.cppreference.com/w/cpp/language/types)
- Python
Python does not have a specific `double` type; instead, it uses `float` to represent both single and double-precision floating-point numbers, automatically providing double precision.
```python myNumber = 3.14 # This is a float in Python, equivalent to double in C++ ```
Official Documentation: s://docs.python.org/3/tutorial/floatingpoint.html(https://docs.python.org/3/tutorial/floatingpoint.html)
- Java
Java's `double` is a primitive data type that stores double-precision floating-point numbers. It is the default choice for decimal values in Java, with a precision of about 15 to 17 decimal digits.
```java double myNumber = 3.14; ```
Official Documentation: s://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html(https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)
- C#
In C#, `double` is a primitive data type that represents a double-precision floating-point number. It is used similarly to Java and C++ for storing real numbers with a high degree of precision.
```csharp double myNumber = 3.14; ```
Official Documentation: s://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types)
- Kotlin
Kotlin also uses the `double` type to represent double-precision floating-point numbers. It is similar to Java, given Kotlin's interoperability with the Java Virtual Machine (JVM).
```kotlin val myNumber: Double = 3.14 ```
Official Documentation: s://kotlinlang.org/docs/basic-types.html#floating-point-types(https://kotlinlang.org/docs/basic-types.html#floating-point-types)
- JavaScript
JavaScript does not differentiate between different types of numbers. All numbers in JavaScript are stored as double-precision floating-point numbers according to the IEEE 754 standard.
```javascript let myNumber = 3.14; // This is a double-precision floating-point number in JavaScript ```
Official Documentation: s://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type)
- TypeScript
TypeScript, being a superset of JavaScript, also does not differentiate between number types. All numbers are double-precision floating-point numbers, similar to JavaScript.
```typescript let myNumber: number = 3.14; // TypeScript uses 'number' for all numeric values, equivalent to double ```
Official Documentation: s://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives(https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#the-primitives)
- PHP
PHP automatically determines the type of a variable at runtime. For numbers, it uses a type similar to `float`, which can include double-precision floating-point numbers. PHP does not have a specific `double` type, but `float` serves the same purpose.
```php $myNumber = 3.14; // PHP treats this as a float, equivalent to double ```
Official Documentation: s://www.php.net/manual/en/language.types.float.php(https://www.php.net/manual/en/language.types.float.php)
- Go
Go has a `float64` type that represents a double-precision floating-point number. It is the Go equivalent of what is typically known as `double` in other languages.
```go var myNumber float64 = 3.14 ```
Official Documentation: s://golang.org/ref/spec#Numeric_types(https://golang.org/ref/spec#Numeric_types)
- Rust
In Rust
, `f64` is used for double-precision floating-point numbers. Rust prefers explicitness, and thus the types `f32` for single precision and `f64` for double precision are used.
```rust let myNumber: f64 = 3.14; ```
Official Documentation: s://doc.rust-lang.org/book/ch03-02-data-types.html#floating-point-types(https://doc.rust-lang.org/book/ch03-02-data-types.html#floating-point-types)
- Swift
Swift uses `Double` for double-precision floating-point numbers. It offers about 15 decimal digits of precision and is the recommended type for storing larger or more precise floating-point numbers.
```swift var myNumber: Double = 3.14 ```
Official Documentation: s://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID322(https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID322)
- Transact-SQL
Transact-SQL uses the `float` data type to store double-precision floating-point numbers. The precision of `float` in Transact-SQL can be specified, and without specification, it defaults to the highest precision, similar to `double`.
```sql DECLARE @myNumber float = 3.14; ```
Official Documentation: s://docs.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql(https://docs.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql)
- PL/SQL
In PL/SQL, the `BINARY_DOUBLE` data type is used for double-precision floating-point numbers. This is equivalent to the `double` type found in other programming languages.
```plsql DECLARE
myNumber BINARY_DOUBLE := 3.14;BEGIN
NULL;END; ```
Official Documentation: s://docs.oracle.com/database/121/LNPLS/datatypes.htm#LNPLS013(https://docs.oracle.com/database/121/LNPLS/datatypes.htm#LNPLS013)
Each of these programming languages has its own way of handling double-precision floating-point numbers, reflecting their unique features and the environments they are designed for. From strictly typed languages like C++ and Java to dynamically typed languages like Python and PHP, the concept of `double` or its equivalent plays a crucial role in representing real numbers with precision.
Fair Use Sources
- 9781617298509 ([2024]])
C++: C++ Fundamentals, C++ Inventor - C++ Language Designer: Bjarne Stroustrup in 1985; C++ Keywords, C++ Built-In Data Types, C++ Data Structures (CPP Containers) - C++ Algorithms, C++ Syntax, C++ OOP - C++ Design Patterns, Clean C++ - C++ Style Guide, C++ Best Practices ( C++ Core Guidelines (CG)) - C++ BDD, C++ Standards ( C++ 23, C++ 20, C++ 17, C++ 14, C++ 11, C++ 03, C++ 98), Bjarne Stroustrup's C++ Glossary, CppReference.com, CPlusPlus.com, ISOcpp.org, C++ Compilers (Compiler Explorer, MinGW), C++ IDEs, C++ Development Tools, C++ Linter, C++ Debugging, C++ Modules ( C++20), C++ Packages, C++ Package Manager ( Conan - the C/C++ Package Manager), C++ Standard Library, C++ Libraries, C++ Frameworks, C++ DevOps - C++ SRE, C++ CI/CD ( C++ Build Pipeline), C++ Data Science - C++ DataOps, C++ Machine Learning, C++ Deep Learning, Functional C++, C++ Concurrency, C++ History, C++ Topics, C++ Bibliography, Manning C++ Series, C++ Courses, CppCon, C++ Research, C++ GitHub, Written in C++, C++ Popularity, C++ Awesome , C++ Versions. (navbar_cplusplus – see also navbar_cpp_containers, navbar_cppcon, navbar_cpp_core_guidelines, navbar_cpp23, navbar_cpp20, navbar_cpp17, navbar_cpp14, navbar_cpp11)
Reserved Words: Programming Language Keywords, aka Reserved Identifiers. (navbar_reserved_words - see also navbar_programming)
© 1994 - 2024 Cloud Monk Losang Jinpa or Fair Use. Disclaimers
SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.