// BuildLang Standard Library - Math Module
// Extended math functions built on top of C math.h builtins (sqrt, sin, etc.).
// ---------------------------------------------------------------------------
// Angle conversion
// ---------------------------------------------------------------------------
fn degrees_to_radians(deg: f64) -> f64 {
deg * 3.14159265358979323846 / 180.0
}
fn radians_to_degrees(rad: f64) -> f64 {
rad * 180.0 / 3.14159265358979323846
}
// ---------------------------------------------------------------------------
// Interpolation and mapping
// ---------------------------------------------------------------------------
fn lerp_f64(a: f64, b: f64, t: f64) -> f64 {
a + (b - a) * t
}
fn map_range(value: f64, in_min: f64, in_max: f64, out_min: f64, out_max: f64) -> f64 {
(value - in_min) / (in_max - in_min) * (out_max - out_min) + out_min
}
// ---------------------------------------------------------------------------
// Distance
// ---------------------------------------------------------------------------
// NOTE: distance_2d requires sqrt which is a math.h builtin recognized at
// the lowering stage but not yet by the type checker. It will work once the
// type checker learns about math builtins. For now, provide distance_squared
// which avoids the sqrt dependency.
fn distance_2d_squared(x1: f64, y1: f64, x2: f64, y2: f64) -> f64 {
let dx = x2 - x1;
let dy = y2 - y1;
dx * dx + dy * dy
}