-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TIP-697: Migrate Floating-Point Calculations from Math to StrictMath #697
Comments
Could you make the above descriptions clearer? eg: what kind of potential impacts it will have when this proposal is approved? |
Can you show which modules will be affected? So that the community can confirm whether the change will affect their own interests |
Currently |
In Java, certain methods in the Math and StrictMath classes may produce inconsistent results, especially when dealing with floating-point arithmetic. This arises because the Math class can utilize platform-specific optimizations, whereas the StrictMath class strictly adheres to the IEEE 754 standard (officially known as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985), also referred to as IEC 60559:1989, which is the standard for binary floating-point arithmetic in microprocessor systems). Here are some methods that may lead to inconsistent results:
Since the methods in the StrictMath class provide precise and consistent results across different platforms, whereas the methods in the Math class may vary due to platform-specific optimizations, the return values of the two can differ in certain scenarios. The only method used in Java-tron code that may result in inconsistent calculation results is |
It is recommended that for future code development, if there are no special reasons to use the Math class, it is always preferred to use the StrictMath class. |
The next step to consider is to migrate directly between Math and StrictMath for computationally consistent methods without requiring a proposal. |
你好,你的邮件我已经收到了。
|
Migrate the |
|
✨✨ Here's an AI-assisted sketch of how you might approach this issue saved by @bAJWA05 using Copilot Workspace v0.27 |
你好,你的邮件我已经收到了。
|
Simple Summary
This TIP proposes migrating Java-Tron's floating-point calculation library from java.lang.Math to java.lang.StrictMath while keeping data consistent and preparing for future JDK version upgrades and multi-platform support.
Motivation
Up to GreatVoyage-v4.7.6(Anaximander), Java-Tron has utilized the class Math for floating-point calculations. However, the class Math may yield varying calculation results for identical inputs across different hardware platforms and JDK versions. As Java-Tron's released versions have exclusively supported JDK8 and x86 environments, data inconsistency issues related to the class Math have not yet emerged.
Looking ahead to potential cross-platform support and broader JDK version compatibility, Java-Tron needs to transition from java.lang.Math to a mathematical library that ensures consistent calculation results across platforms and newer JDK versions.
This TIP also examines maintaining data consistency throughout the TRON network during the migration process without impacting consensus dating back to the genesis block.
Specification
As noted above, the class java.lang.Math may produce different calculation results across platforms and multiple JDK versions. Although this hasn't affected Java-Tron's data consistency due to limited platform and JDK version support, replacing the java.lang.Math class is essential for future cross-platform and multi-JDK version support.
According to Java's official documentation, class java.lang.StrictMath provides the equivalent functions of class java.lang.Math can produce the same results across different hardware platforms and the JDK versions. This makes java.lang.StrictMath is an ideal replacement for the java.lang.Math class in this scenario.
Hence, we propose implementing a uniform replacement of the java.lang.Math class with java.lang.StrictMath class throughout Java-Tron via this proposal.
It's important to note that the java.lang.StrictMath class may exhibit slight variations in calculation results compared to the java.lang.Math library in certain scenarios. This TIP will list all relevant differences in Java-Tron and analyze their potential impact on consensus. Any changes affecting consensus will only be implemented network-wide after proposal approval, ensuring the Math class migration does not compromise data consistency.
Rationale
StrictMath guarantees reproducible results, independent of the JDK version, hardware implementation, etc. To help ensure the portability of Java programs, the numeric functions in this class require that they produce the same results as certain published algorithms. These algorithms are available from the well-known network library Netlib as the package "Freely Distributable Math Library."
Key differences between Math and StrictMath:
Backwards Compatibility
Since consensus-affecting changes will only be activated post-proposal approval, this migration maintains backward compatibility and preserves consensus from the genesis block onward.
Implementation
Stage 1
Migrate the pow operation from
java.lang.Math
tojava.lang.StrictMath
will be activated by proposal No 87 in this PR:pow
operation from java.lang.Math to java.lang.StrictMath java-tron#6098.Stage 2
Migrate all other operations from
java.lang.Math
tojava.lang.StrictMath
.Currently, Tron uses Math in the following methods, and after analyzing the results of the calculations, there is no problem replacing it with StrictMath.
The text was updated successfully, but these errors were encountered: