## [Library Scripts] String Maths by B O F

The place to discuss scripting and game modifications for X³: Reunion.
B-O'F
Posts: 719
Joined: Sat, 21. Feb 04, 03:15

### [Library Scripts] String Maths by B O F

String Maths Library

V1 - 2008/02/30

Do you want to use really large numbers?

Do you want to use really small numbers?

Do you need to mix really large numbers and small numbers?

Do you wish you could use decimal numbers?

This is a package to support arithmetic operations on numeric strings - O.K. I named it String Maths, but it is really String Arithmetic..

It works on:-
- numeric strings,
- signed numeric strings - leading or trailing signs.
- decimal strings (sign optional).

It performs:-
- '-' Subtract
- '*' Multiply
On decimal and/or non-decimal strings.

- '/' Divide - non-decimal returns quotient and remainder in an array, decimal returns a decimal string.
- '//' Forced Divide - return a decimal result from two non-decimal input strings.

It currently supports a choice of two decimal point characters - main.44 uses a full stop while main.49 uses a comma.
You can add your own character to use as a decimal point if you require it. Instructions are in the "Usage" file and in the main.xx scripts themselves.

You can also select whether to have leading '+' signs included or not - there is no choice for negative result strings, they will always have a leading '-' sign.

Decimal output is to a default of 20 decimal places, if either input string has more, then that is taken as the default. It also includes rounding to the selected number of places.

The output is normally a signed string, the exceptions are:-
- Non-decimal divide will return an array of quotient and remainder.
- An error will return a NUMBER, not a string. See "Usage" for how to cope with these different outputs.

The only ouput message from the basic library is from the main.xx - if you specify a decimal point string rather than a single character.
The additional script to format the output for display does issue error mesages, as it is also meant for stand-alone use.

This package contains:
* All the scripts required to perform the above.