Here's a bunch of small, self-contained utility routines for vector arithmetic, random numbers, mathematical functions, computer graphics, and generic portability and networking. They're written in C++, but they don't go crazy with templates, and you'll be able to figure out what they do by reading the header. They're all public domain (free for any use, even commercial use) so you'll never have any license or copyright headaches.

Download the whole thing as an 80KB zip file, or a tar-gzip file.

OSL contents include:

Of particular scientific computing and mathematical interest: vector1d,2d,3d,4d: spatial vector class, with +, -, dot, cross, etc. random.h/.cpp: pseudorandom number generators for ints, floats, etc. random_vector.h: 2D and 3D random vectors over cubes and spheres. least_squares.h/.cpp: linear least-squares function fitting. statistics.h: means, variances, standard deviations in an easy interface. matrix.h/.cpp: a dynamically allocated arbitrary-size matrix. fn1d.h: 1D function root-finding, with bisection and secant methods. Of particular computer graphics interest: vector1d,2d,3d,4d: spatial vector class, with +, -, dot, cross, etc. vector_util.cpp: non-inlined routines for vector1d-4d. viewpoint.h/.cpp: 3D projective camera class. perlin_noise.h/.cpp: smooth 3D noise function (by Ken Perlin). Of particular portability and networking interest: dir.h/.cpp: portable directory traversal (list files in a directory) dll.h/.cpp: portable dynamically linked library interface. socket.h/.cpp: portable easy-to-use TCP socket wrapper. sha1.h/.cpp: Secure Hash Algorithm-1. FIPS standard crypto hash. authpipe.h/.cpp: network protocol for secret-key authentiated messaging. In alphabetical order: authpipe.h/.cpp: network protocol for secret-key authentiated messaging. bbox2d.h/bbox3d.h: 2D/3D bounding box routines, with box intersection, union, and creation from points. dir.h/.cpp: portable directory traversal (list files in a directory) dll.h/.cpp: portable dynamically linked library interface. fast_math.h: float-to-integer conversion, but faster than (int)f. fn1d.h: 1D function root-finding, with bisection and secant methods. integrate.h: decompose a 2D polygon into trapezoids for easy integration. Includes routines for center of mass and moment of inertia. least_squares.h/.cpp: linear least-squares function fitting. matrix2d.h: a 3x3 matrix, for 2D rotation/translation/scale/skew matrix3d.h: a 4x4 matrix, for 3D rotation/translation/scale/skew/projection matrix_util.cpp: implementation of 2D and 3D routines not in headers. matrix.h/.cpp: a dynamically allocated arbitrary-size matrix. matrixpower.h/.cpp: raise a Matrix2d to a fractional power. matrixT.h: a fast templated fixed-size matrix. Used by 2D and 3D matrices. ndarray.h: an N-dimensional allocatable array. perlin_noise.h/.cpp: smooth 3D noise function (by Ken Perlin). pointinpolygon.h: determine if a point is inside a 2D polygon. polygon.h/.cpp: determine 2D polygon's area, center of mass, inertia, ... random.h/.cpp: pseudorandom number generators for int, float, etc. Using "osl::Random48" or better is recommended for Monte Carlo. random_vector.h: 2D and 3D random vectors over cubes and spheres. sha1.h/.cpp: Secure Hash Algorithm-1. FIPS standard crypto hash. socket.h/.cpp: portable easy-to-use TCP sockets. spheretrig.h/.cpp: areas and angles measured along a sphere. statistics.h: means, variances, standard deviations in an easy interface. vector1d,2d,3d,4d: spatial vector class, with +, -, dot, cross, etc. vector_util.cpp: non-inlined routines for vector1d-4d. viewpoint.h/.cpp: 3D projective camera class.