Add exact arithmetic implementation and tests

- Introduced exact arithmetic with support for large integers and fractions in `exact.gd`, `big_integer.gd`, and `exact_value.gd`.
- Implemented a comprehensive test suite in `test_exact_math.gd` to validate arithmetic operations against expected results.
- Added a README in `math` directory to document the exact arithmetic system and its usage.
- Ensured that all arithmetic operations maintain precision without floating-point errors, using a custom representation for large numbers.
- Included methods for encoding and decoding exact values for serialization.
This commit is contained in:
Kirill
2026-09-30 08:08:27 +03:00
parent f2111a376a
commit fb8a3f5658
58 changed files with 5139 additions and 2162 deletions
+6 -5
View File
@@ -1,4 +1,5 @@
extends RefCounted
const E = preload("res://world/owniverse/math/exact.gd")
const Parameters = preload("res://world/owniverse/world_parameters.gd")
var energy_bars: Array = []
@@ -32,21 +33,21 @@ func _ignore_mouse_on_children(node: Node) -> void:
func update(world) -> void:
var source: Dictionary = world.state
var energy: float = clampf(source.energy / Parameters.INITIAL_ENERGY, 0.0, 1.0)
var energy: float = E.approx(E.clamp_value(E.divide(source.energy, Parameters.INITIAL_ENERGY), 0, 1))
for bar in energy_bars: bar.scale.x = energy
var density_value: float = world.environment.stellar_environment(source).density
var density_value = world.environment.stellar_environment(source).density
var density: Dictionary = Parameters.density_display(density_value)
warning_border.self_modulate = Parameters.density_warning_color(density_value)
for indicator in density_indicators:
for mode in ["Density", "DensityRip", "DensityCrunch"]:
indicator.get_node(mode).visible = mode == density.mode
var pointer: Control = indicator.get_node("Pointer")
pointer.position.x = 16.0 + 288.0 * density.position - pointer.size.x / 2.0
pointer.position.x = 16.0 + 288.0 * E.approx(density.position) - pointer.size.x / 2.0
pointer.self_modulate = Color.BLACK if density.mode == "DensityCrunch" else Color.WHITE
for key in pointers:
var pointer: Control = pointers[key]
pointer.position.x = 16.0 * clampf(Parameters.value(source, key), 1.0, 19.0) - pointer.size.x / 2.0
pointer.position.x = 16.0 * E.approx(E.clamp_value(Parameters.value(source, key), 1, 19)) - pointer.size.x / 2.0
for i in trend_bars.size():
var bar: Control = trend_bars[i]
bar.pivot_offset = Vector2(0.0, bar.size.y)
bar.scale.y = clampf(source.get("trends", {}).get(Parameters.TRENDS[i], 0.0), 0.0, 1.0)
bar.scale.y = E.approx(E.clamp_value(source.get("trends", {}).get(Parameters.TRENDS[i], 0), 0, 1))