bordemstirs
Member
mathlib:1.6
[size=+1]Math Library[/size]
Introducing Mathlib, a concise set of mathematical functions that aren't currently in ASH.
Some of these functions will be more useful than others in the given context, but the goal here was purely for fun. So, what does it do you ask? Why, let me show you.
string to_string(float number, int precision, boolean trailing)
string to_string(float number, int precision)
Simple extension to the existing to_string function, but with precision options, and, optionally, additional zeroes if there are less numbers after the decimal than the specified precision.
void throw(int error, string custom, boolean abort)
void throw(int error, string custom)
void throw(int error, boolean abort)
void throw(int error)
Error handler. Prints error messages based on error number, optionally add a custom message, and aborts if abort is set.
float fact(int x)
Standard factorial function. Throws an error if x is greater than 13, that's ASH's integer limit.
int bitSet(int x, int mask)
int bitUnset(int x, int mask)
int bitToggle(int x, int mask)
Modifying specific bits in integer x. Mask here refers to the the decimal value of the bits to modify, not the location. (i.e. to set LSBs 1 and 3, you'd pass mask "5")
int bitAnd(int A, int B)
int bitOr(int A, int B)
int bitXor(int A, int B)
int bitNot(int A)
The standard bitwise operators AND (&), OR (|), XOR (^), and NOT (~) for your bit manipulating pleasure. These functions were my main reason for starting this library, the rest just sort of fell in.
boolean flagSet(int x, int mask)
Checks x to see if the bits defined by mask are set.
boolean odd(int x)
Returns true if x is an odd number.
float sqrt(float x)
Returns square root of x.
float sin(float x, boolean deg, int prec)
float sin(float x, boolean deg)
float sin(float x, int prec)
float sin(float x)
float cos(float x, boolean deg, int prec)
float cos(float x, boolean deg)
float cos(float x, int prec)
float cos(float x)
float tan(float x, boolean deg, int prec)
float tan(float x, boolean deg)
float tan(float x, int prec)
float tan(float x)
All your basic trig functions.
Currently they are fairly accurate, but until I expand factorial to float, or mafia's float gets more accurate, precision seems to cap out around 8 decimal points.
float ln(float x, int prec)
float ln(float x)
Standard natural log function.
float mathlibeval(string expression)
float mathlibeval(string expression, float[string] variables)
My pride and joy. Similar to modifier_eval() and Zlib's eval() but with support for more standard functions and many of the functions included in mathlib.
While the trig functions can be passed with the degree boolean, it currently doesn't accept the precision parameter, and will merely ignore it.
Currently supports the functions included in standard modifier_eval() plus the following:
rand, fact, sin, cos, tan, throw, not, and, xor, or, and round.
Simply throw this in your script, and you're good to go:
Thank you, I hope you enjoy and I hope at least one scripter puts this to use.
--Almighty Sapling
changelog
2010.11.26: file introduced
2010.11.26: trig functions complete. Added update feature and boolean odd(int)
2010.11.28: fact() changed; Added float mathlibeval(string,float[string]), float sqrt(float)
2010.12.09: Added float ln(float,int), boolean flagSet(int,int), minor change to version control.
2010.12.09: fixed my failure. I fail.
[size=+1]Math Library[/size]
Introducing Mathlib, a concise set of mathematical functions that aren't currently in ASH.
Some of these functions will be more useful than others in the given context, but the goal here was purely for fun. So, what does it do you ask? Why, let me show you.
string to_string(float number, int precision, boolean trailing)
string to_string(float number, int precision)
Simple extension to the existing to_string function, but with precision options, and, optionally, additional zeroes if there are less numbers after the decimal than the specified precision.
void throw(int error, string custom, boolean abort)
void throw(int error, string custom)
void throw(int error, boolean abort)
void throw(int error)
Error handler. Prints error messages based on error number, optionally add a custom message, and aborts if abort is set.
float fact(int x)
Standard factorial function. Throws an error if x is greater than 13, that's ASH's integer limit.
int bitSet(int x, int mask)
int bitUnset(int x, int mask)
int bitToggle(int x, int mask)
Modifying specific bits in integer x. Mask here refers to the the decimal value of the bits to modify, not the location. (i.e. to set LSBs 1 and 3, you'd pass mask "5")
int bitAnd(int A, int B)
int bitOr(int A, int B)
int bitXor(int A, int B)
int bitNot(int A)
The standard bitwise operators AND (&), OR (|), XOR (^), and NOT (~) for your bit manipulating pleasure. These functions were my main reason for starting this library, the rest just sort of fell in.
boolean flagSet(int x, int mask)
Checks x to see if the bits defined by mask are set.
boolean odd(int x)
Returns true if x is an odd number.
float sqrt(float x)
Returns square root of x.
float sin(float x, boolean deg, int prec)
float sin(float x, boolean deg)
float sin(float x, int prec)
float sin(float x)
float cos(float x, boolean deg, int prec)
float cos(float x, boolean deg)
float cos(float x, int prec)
float cos(float x)
float tan(float x, boolean deg, int prec)
float tan(float x, boolean deg)
float tan(float x, int prec)
float tan(float x)
All your basic trig functions.
Currently they are fairly accurate, but until I expand factorial to float, or mafia's float gets more accurate, precision seems to cap out around 8 decimal points.
float ln(float x, int prec)
float ln(float x)
Standard natural log function.
float mathlibeval(string expression)
float mathlibeval(string expression, float[string] variables)
My pride and joy. Similar to modifier_eval() and Zlib's eval() but with support for more standard functions and many of the functions included in mathlib.
While the trig functions can be passed with the degree boolean, it currently doesn't accept the precision parameter, and will merely ignore it.
Currently supports the functions included in standard modifier_eval() plus the following:
rand, fact, sin, cos, tan, throw, not, and, xor, or, and round.
Simply throw this in your script, and you're good to go:
Code:
import <mathlib.ash>
Thank you, I hope you enjoy and I hope at least one scripter puts this to use.
--Almighty Sapling
changelog
2010.11.26: file introduced
2010.11.26: trig functions complete. Added update feature and boolean odd(int)
2010.11.28: fact() changed; Added float mathlibeval(string,float[string]), float sqrt(float)
2010.12.09: Added float ln(float,int), boolean flagSet(int,int), minor change to version control.
2010.12.09: fixed my failure. I fail.
Attachments
Last edited: