Repository navigation
2.2 Decimals
float a = 1.0;
double a2 = 2.0;
##注意事项
1使用var来定义小数的时候,类型默认为双精度浮点数;
2根据IEEE 754 浮点数计算标准,小数在原生计算时由分数表示,这会造成浮点数精度问题:0.1 + 0.2 不等于 0.3 而是0.30000000000000004
3浮点数在数值为 NaN (Not a number)的情况下会出现一系列问题,请不要让它这么计算。
4当小数参加运算时,最终结果的类型会自动提升。
5当你尝试使用null+1.0时,脚本会报错(java.lang.NullPointerException)
6无限精度的四则运算函数将会在函数章节提及。
7本DSL不建议直接比较纯小数的大小。
1 When using var to define decimals, the default type is double-precision floating-point number.
2 According to the IEEE 754 floating-point calculation standard, decimals are represented by fractions during native calculations, which causes floating-point precision issues: 0.1 + 0.2 does not equal 0.3, but 0.30000000000000004.
3 A series of problems will occur when the floating-point number has a value of NaN (Not a number). Please do not let it perform such calculations.
4 When decimals participate in operations, the type of the final result will be automatically promoted.
5 When you try to use null + 1.0, the script will report an error (java.lang.NullPointerException).
6 The four arithmetic operation functions with infinite precision will be mentioned in the function section.
7 It is not recommended to directly compare the magnitudes of pure decimals in this DSL.
- 首页 / Home
- 安装与快速开始 / Installation & Quick Start
- 第一个脚本 / Your First Script
- 命令速查 / Command Reference
- 自动执行脚本 / Auto-run Scripts
- 定义函数 / Defining Functions
- 函数重载 / Function Overloading
- Lambda 表达式 / Lambda Expressions
- 函数式接口 / Functional Interfaces
- 选择器总览 / Selectors Overview
- 选择器过滤器 / Selector Filters
- EntityRef 引用 / EntityRef
- 占位符参考 / Placeholders Reference
- PlaceholderAPI 桥接 / PAPI Bridge
- 创建 GUI / Creating a GUI
- GUISlot 槽位 / GUISlot
- 点击回调 / Click Callbacks
- onClose 回调 / onClose Callback
- GUI 刷新 / GUI Refresh
- 数学函数 / Math Built-ins
- 高精度计算 / BigDecimal Built-ins
- 字符串函数 / String Built-ins
- 集合函数 / Collection Built-ins
- 文件 I/O / File I/O
- 命令与 sleep / Commands & sleep