A consolidated Math Library suite for the Carp programming language.
- Color: See module documentation below.
- Fft: See module documentation below.
- Matrix: See module documentation below.
- Noise: See module documentation below.
- Simd: See module documentation below.
- Transform: See module documentation below.
See examples.md for module usage examples.
A graphics-oriented color library for the Carp language.
- RGB & RGBA Support: Precise
Doublebased color representation. - HSL Color Space: Full support for HSL with robust RGB <-> HSL conversions.
- Manipulation: Helpers for
lighten,darken,saturate,desaturate, andlerp. - Hex Strings: Parse from and format to standard hex codes (e.g.,
#ff0000). - Byte Helpers: Easy conversion to/from 0-255 byte ranges for interoperability with SDL, OpenGL, etc.
Add this to your project by loading color.carp.
(load "path/to/carp-color/color.carp")
(use Color)carp -x test/color_test.carpSee examples.md for usage examples.
MIT
A robust, low-level numerical matrix library for the Carp language.
- Safe & Unsafe API: Choose between performance and safety with
Result-returning functions orunsafe-variants. - True In-Place Mutation: Memory-efficient operations like
add!,sub!, andhadamard!that modify data without new allocations. - Cache-Aware Performance: Optimized matrix multiplication using transposed layouts for better cache locality.
- Zero-Copy Structural Ops: Metadata-only
reshapeandflatten(currently behaves as copy due to Carp deftype semantics, but architected for minimal overhead). - Comprehensive API: Includes
zeros,identity,random,transpose,dot,mat-vec,outer-product,approx=, and more. - Rigorous Testing: Deep verification of mathematical identities and edge cases.
Add this to your project by loading matrix.carp.
(load "path/to/carp-matrix/matrix.carp")
(use Mat)carp -x test/matrix_test.carpSee examples.md for usage examples.
MIT
A fast, seeded Simplex Noise implementation for the Carp programming language.
- Seeded Noise State: Independent noise generators that do not rely on global RNG state.
- 2D & 3D Simplex Noise: Implementation based on the canonical Simplex algorithms.
- Fractal Brownian Motion (FBM): Composable fractal noise with configurable octaves, persistence, and lacunarity.
- Performance: Uses unsafe array access for hot paths and avoids allocations during sampling.
Clone this repository into your project or add it as a submodule:
git submodule add https://github.com/sqrew/carp-noise.gitSee examples.md for usage examples.
(let [state (make-noise 123)
config (FBMConfig.init 6 0.5 2.0)
val (fbm2d &state 0.1 0.2 &config)]
(IO.println &(Double.to-string val)))
Run the test suite with:
carp -x test/noise_test.carpThis project is licensed under the MIT License.
A robust, double-precision Fast Fourier Transform (FFT) and Digital Signal Processing (DSP) library for the Carp language.
The library is separated into focused modules for easier extension and maintainability:
-
Complex Numbers (
complex.carp): Loaded via dependency carp-complex-numbers, providing double-precision complex arithmetic (+,-,*,/,abs/norm, conjugate, exponentiation, trigonometric functions, etc.). -
Main Transforms (
fft.carp):- 1D FFT & IFFT (
fft,ifft,try-fft,try-ifft) using a Cooley-Tukey Radix-2 decimation-in-time algorithm. - Real FFT (
rfft,rfft-one-sided) and Complex-to-Real IFFT (irfft) which takes a one-sided spectrum (size$N/2 + 1$ ) and automatically reconstructs Hermitian symmetry before transforming. - 2D FFT & IFFT (
fft2d,ifft2d,try-fft2d,try-ifft2d) via row-column decomposition. - Signal utilities like zero-padding (
pad-zero,pad-zero-complex) and zero-frequency shifting (fftshift,ifftshift).
- 1D FFT & IFFT (
-
Signal Windowing (
window.carp): Common window generators (Hann, Hamming, Blackman, Rectangular, Bartlett/Triangular, Gaussian, and Flat Top) with in-place multipliers (apply!,apply-real!). -
Spectral Analysis (
spectrum.carp): Functions to calculate magnitude, power, natural log, and decibel (dB) log-magnitude spectra (magnitude,power,log-spectrum,db). -
Signal Convolution (
convolution.carp): High-performance spectral domain operations: circular convolution (circular-convolve), linear convolution (convolve), cross-correlation (cross-correlate), and autocorrelation (autocorrelate).
Add the library files to your project:
(load "path/to/carp-fft/complex.carp")
(load "path/to/carp-fft/fft.carp")
(load "path/to/carp-fft/window.carp")
(load "path/to/carp-fft/spectrum.carp")
(load "path/to/carp-fft/convolution.carp")
(use Complex)
(use FFT)
(use Window)
(use Spectrum)
(use Convolution)Run the comprehensive test suite (verifying DSP behaviors like Impulse, Alternating/Nyquist spikes, Parseval's theorem, convolutions, and roundtrips):
carp -x test/fft_test.carpSee examples.md for usage examples.
MIT
A high-performance, architecture-scaling SIMD (Single Instruction Multiple Data) library for the Carp programming language.
This library leverages GCC/Clang Vector Extensions to compile dynamic vector math operations directly to native CPU SIMD instructions (SSE/AVX on x86_64, NEON on ARM/Apple Silicon), with zero heap allocation or runtime call overhead.
- Auto-Scaling Lane Width: Detects target hardware architecture at compile time, adapting lane size dynamically:
- AVX-512 (
__AVX512F__): 16 Float lanes (512-bit registers) - AVX / AVX2 (
__AVX2__): 8 Float lanes (256-bit registers) - SSE / NEON (Default): 4 Float lanes (128-bit registers)
- AVX-512 (
- Zero-Overhead Primitives: Emits inline operators (
+,-,*,/) that standard C compilers vectorize directly into CPU instruction pipelines. - Pointer Loads/Stores: Low-level functions to load and store batches of floats directly to and from contiguous arrays.
See examples.md for usage examples.
To enable wider registers (like AVX2), pass the architecture flags to your C compiler when running carp:
carp -x main.carp --cflag="-mavx2"MIT
A high-performance 3D transformation library for the Carp programming language.
This library provides a standardized way to manage the spatial state (Position, Rotation, Scale) of game objects. It uses Quaternions for stable rotations and generates 4x4 matrices compatible with WGPU.
- Matrix Layout: Column-major (OpenGL/WGPU style).
- Coordinate System: Right-handed.
- Rotation: Hamilton product quaternions.
- Euler Convention: YXZ intrinsic (Yaw-Pitch-Roll).
- Quaternion Support: Stable 3D rotations with automatic normalization to prevent drift.
- Basis Extraction: Easily get
forward,right, andupvectors from any transform. - TRS to Matrix: Efficiently generates
TransformMat4(M = T * R * S). - Standardized: Built on Carp's internal
Vector3library.
See examples.md for usage examples.
MIT
MIT