ASL
Loading...
Searching...
No Matches
Global functions

Detailed Description

These utilities allow simple code like:

Measuring time and sleeping for some time:

double t1 = now();
sleep(0.5); // sleep for 500 ms
double t2 = now();
double elapsed = t2 - t1; // -> around 0.5
double now()
Returns the current time as a real number in seconds since a fixed epoch (precision is platform-depen...

Convert radians to degrees and limit to 0-360 deg interval:

double degrees = clamp(rad2deg(angle), 0, 360);
T clamp(T x, C a, C b)
Clamps the value of x to make it lie inside the [a,b] interval.
Definition defs.h:208

Get random numbers in an interval:

double x = random(-1.0, 1.0);
String item = names[ random( names.length() ) ]; // pick random array item

Turn a file into a base64 representation:

TextFile("image.jpg.b64").put( encodeBase64(File("image.jpg").content()) );

Typedefs

typedef unsigned char byte
 An unsigned byte.
 

Functions

float infinity ()
 Returns +infinity.
 
float nan ()
 Returns a NaN value.
 
template<class T >
sqr (T x)
 Returns x squared.
 
template<class T >
fract (T x)
 Returns the fractional part of x
 
template<class T >
round (T x, T k)
 Rounds a number to a multiple of k.
 
template<class T , class C >
clamp (T x, C a, C b)
 Clamps the value of x to make it lie inside the [a,b] interval.
 
template<class T >
deg2rad (T x)
 Returns x degrees converted to radians.
 
double deg2rad (int x)
 Returns x degrees converted to radians, exceptionally treating ints as doubles so you can safely do deg2rad(45)
 
template<class T >
rad2deg (T x)
 Returns x radians converted to degrees.
 
double now ()
 Returns the current time as a real number in seconds since a fixed epoch (precision is platform-dependent, often around a microsecond).
 
void sleep (double s)
 Makes the current thread sleep for the given time in seconds (can be fractional)
 
void usleep (int us)
 Makes the current thread sleep for the given time in microseconds.
 
ByteArray decodeBase64 (const String &s)
 Decodes a base64 encoded string into a byte array; the string can contain whitespace.
 
String encodeBase64 (const ByteArray &s)
 Encodes a byte array as a string using base64 encoding.
 
String encodeBase64 (const String &s)
 Encodes a string as a string using base64 encoding.
 
String encodeHex (const ByteArray &src)
 Encodes a byte array as a string using hexadecimal.
 
ByteArray decodeHex (const String &src)
 Decodes a hexadecimal encoded string into a byte array.
 

Typedef Documentation

◆ byte

typedef unsigned char byte

An unsigned byte.

This is also included in the global scope (using asl::byte;) for compatibility with old code, unless ASL_NO_GLOBAL_BYTE is defined.

Deprecated:
This type will not be added to the global scope anymore; code should use asl::byte