search
HomeComputer TutorialsComputer KnowledgeWhat are java floating point constants

What are java floating point constants

What are java floating point constants

Floating point data type represents real numbers, including decimal parts. Real-world data is complex and requires data types that support real numbers.

1. Floating-point constants Java’s real constants have two representation forms: decimal number form, which consists of numbers and decimal points, and must have a decimal point, such as 0.123, .123, 123., 123.0. 2. Scientific notation form. For example: 123e3 or 123E3, where there must be a number before e or E, and the exponent after e or E must be an integer. Real constants occupy 64 bits in the machine and have double values. For float type values, f or F must be added after the number, such as 12.3F, which occupies 32 bits in the machine and has low representation precision.

Floating point variables have two types: float and double. Float occupies 32 bits, and the value range is 3.4e-038~3.4e 038; while double occupies 64 bits, and the value range is 1.7e-308~1.7e 308. The double type has higher precision and a larger representation range than the float type, and is usually used in scenarios that require high precision, such as scientific calculations.

In Java, you can use float and double to define floating-point variables. For example: float f; // Specify variable f as float type double d; // Specify variable d as double type Unlike C and C, Java does not have an unsigned integer type and specifies the number of memory bytes occupied by integer and floating-point data. This provision ensures the security, robustness and platform independence of Java programs. This means that different Java implementations have consistent behavior when dealing with integer and floating point data, and the results are predictable regardless of the platform they are running on.

java floating point calculation problem

Bit operations are usually used in hardware control. The expression itself cannot determine the specific meaning and needs to be combined with the actual scenario.

& is called "bitwise AND", and its rules are: 0&0=0 1&0=0 0&1=0 1&1=1

"|" is called "bitwise OR", and the operation rules are: 0|0=0 1|0=1 0|1=1 1|1=1

0x7fffff is expressed in 32-bit binary as 0000 0000 0111 1111 1111 1111 1111 1111

According to the bitwise AND operation rule, the high 9 bits of bits are cleared to zero.

0x800000 is expressed in 32-bit binary as 0000 0000 1000 0000 0000 0000 0000 0000

According to the bitwise OR algorithm, the 24th bit is set to 1.

To put it in perspective, ((bits & 0x7fffff)|0x800000) means to clear the high 9 bits of bits first, and then set the 24th bit to 1.

Regarding the first half, "

As for the question mark, there’s no need to explain it, right?

A JAVA question about floating point types

Floating point numbers will have errors after operations, which is normal.

double a=2.00-1.10;

double b=0.90;

System.out.print(a==b);

The result will be false

So sometimes a method is used when judging the equality of floating point numbers, that is

public static boolean isEqual(double a,double b){

final double epsilon=0.00000001;

return Math.abs(a-b)

}

To sum up, errors will occur after floating point numbers are processed. 0.7799999713897705 is the error caused by converting float to double, and 0.78 is the normal operation of float

The above is the detailed content of What are java floating point constants. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Excel办公网. If there is any infringement, please contact admin@php.cn delete
How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)Mar 11, 2025 am 11:26 AM

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

ENE SYS Maintenance: Tips and Tricks to Keep Your System Running SmoothlyENE SYS Maintenance: Tips and Tricks to Keep Your System Running SmoothlyMar 07, 2025 pm 03:09 PM

This article provides practical tips for maintaining ENE SYS systems. It addresses common issues like overheating and data corruption, offering preventative measures such as regular cleaning, backups, and software updates. A tailored maintenance s

5 Common Mistakes to Avoid During ENE SYS Implementation5 Common Mistakes to Avoid During ENE SYS ImplementationMar 07, 2025 pm 03:11 PM

This article identifies five common pitfalls in ENE SYS implementation: insufficient planning, inadequate user training, improper data migration, neglecting security, and insufficient testing. These errors can lead to project delays, system failures

How do I edit the Registry? (Warning: Use with caution!)How do I edit the Registry? (Warning: Use with caution!)Mar 21, 2025 pm 07:46 PM

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

Discover How to Fix Drive Health Warning in Windows SettingsDiscover How to Fix Drive Health Warning in Windows SettingsMar 19, 2025 am 11:10 AM

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

How do I manage services in Windows?How do I manage services in Windows?Mar 21, 2025 pm 07:52 PM

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

which application uses ene.syswhich application uses ene.sysMar 12, 2025 pm 01:25 PM

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

why won't driver asio.sys loadwhy won't driver asio.sys loadMar 10, 2025 pm 07:58 PM

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft