[Lib] Exact division (using modular arithmatic)

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Post Reply
Osiris_sam
Posts: 422
Joined: Thu, 24. Aug 06, 13:45
x4

[Lib] Exact division (using modular arithmatic)

Post by Osiris_sam » Thu, 23. Jul 09, 13:44

Exact division
Link

Usage:
Input:
-> number ~ the number you want to divide
-> number to divide by ~ the number you want to divide by (must be non 0)
-> Accuracy ~ number of decimal points to calculate to. setting this to 0 will return a number, setting to 1, 2, 3 or 4 will return that number of decimal points

this script will return the answer in string form. i was going to write string arithmatic libraries, but while testing, it kept freezing and idk why.

Theory: for anyone interested
this script calculates the answer in two parts, as an integer, and as a decimal.
the interger componnet is calculated by the normal method.
the decimal component is calculated by finding the remainder when x is divided by y, multiplying that by the accuracy coefficient, and then dividing by y. (using the mod function)

have fun,
sam

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”