Handling Extremely Large Numbers
264,220 Views
-
using { /Verse.org/Simulation } ################################# # We can represent very big numbers as a struct containing both a value and an exponent ################################# big_number := struct <concrete>: @editable Value : float = 0.0 @editable Exponent : int = 0 ################################# # Below are various functions to operate on big numbers ################################# # Adds two big_numbers together BigNumber_Add(NumberA : big_number, NumberB : big_number):big_number= CommonExponent : int = Max(NumberA.Exponent, NumberB.Exponent) NewValue : float = (NumberA.Value * Pow(10.0, (NumberA.Exponent - CommonExponent) * 1.0)) + (NumberB.Value * Pow(10.0, (NumberB.Exponent - CommonExponent) * 1.0)) BigNumber_Normalize(big_number{Value := NewValue, Exponent := CommonExponent})
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.