search
HomeCommon Problem3.14 Is it float type or double type?

3.14 Is it float type or double type?

Jul 06, 2020 pm 03:55 PM
doublefloatfloating point number

3.14 is double type. Because the representation of 3.14 as a decimal in a computer is basically impossible to describe accurately and is generally just an approximation, so "3.14f" can be expressed as a float type, while 3.14 can only be expressed as a double type.

3.14 Is it float type or double type?

3.14 is double type

1. The double data type is similar to the single precision data type (float), but The accuracy is higher than float, and the memory space occupied during compilation varies according to different compilers.

Usually, single-precision floating point numbers occupy 4 bytes (32 bits) of memory space, and their numerical range It is -3.4E38~3.4E 38; the double precision type occupies 8 bytes (64 bits) of memory space, and its value range is -1.7E308~1.7E 308.

3.14 The representation of decimals in computers cannot be accurately described. It is generally just an approximation (except for special examples such as 0.5). This is why we cannot use floating point numbers to compare. ==, but uses the difference between two numbers to indicate that the two numbers are equal within a small range.

So 3.14f can be expressed as float type, and 3.14 can only be expressed as double type.

2. Declare a variable of double type: double puotient; initialize a variable of double type: puotient = 5.621456873; double puotinet = 5.62.

3. Float is generally 4 bytes, double is generally 8 bytes, and the range is larger than float.

3.14 Is it float type or double type?

Extended information:

1. In C language, double precision floating point (double) type, occupies 8 bytes (64-bit) memory space. The numerical range is -1.7E308~1.7E 308. Double precision is fully guaranteed to have 15 significant digits, and 16 bits are only guaranteed for some values. Single precision guarantees 7 significant digits, and some values ​​have 8 significant digits.

Floating point type is scientific notation in a narrow sense, double precision, that is, double. Double means two, two.

2. The C standard requires that the float type has a precision of 7 digits, and the representation range of the integer part must be at least -1.0E37 -- 1.0E 37. float is generally 32-bit.

The C standard stipulates that the minimum representation range of the integer part of the double type is the same as that of float, which is -1.0E37 to 1.0E37, but it requires the precision of the double type to be 15 to 16 bits. double is usually 64 bits. The control character for outputting double float type is %lf. When a variable is defined, it can be abbreviated as double.

3. Floating-point data type. The FLOAT data type is used to store single-precision floating-point numbers or double-precision floating-point numbers.

Floating point numbers use IEEE (Institute of Electrical and Electronics Engineers) format. Single-precision values ​​of floating-point type have 4 bytes, including a sign bit, an 8-bit excess-127 binary exponent, and a 23-bit mantissa. The mantissa represents a number between 1.0 and 2.0.

Since the high-order bit of the mantissa is always 1, it is not stored as a number. This representation gives the float type a range between approximately -3.4E-38 and 3.4E-38.

For more related knowledge, please visit PHP Chinese website! !

The above is the detailed content of 3.14 Is it float type or double type?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor