Phase 8: Std::Math module + comprehensive feature showcase demo
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
module Std::Math {
|
||||||
|
|
||||||
|
extern func bux_sqrt(x: float64) -> float64;
|
||||||
|
extern func bux_pow(x: float64, y: float64) -> float64;
|
||||||
|
extern func bux_abs_i64(x: int64) -> int64;
|
||||||
|
extern func bux_abs_f64(x: float64) -> float64;
|
||||||
|
extern func bux_min_i64(a: int64, b: int64) -> int64;
|
||||||
|
extern func bux_max_i64(a: int64, b: int64) -> int64;
|
||||||
|
extern func bux_min_f64(a: float64, b: float64) -> float64;
|
||||||
|
extern func bux_max_f64(a: float64, b: float64) -> float64;
|
||||||
|
|
||||||
|
func Sqrt(x: float64) -> float64 {
|
||||||
|
return bux_sqrt(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
func Pow(x: float64, y: float64) -> float64 {
|
||||||
|
return bux_pow(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
func Abs(n: int64) -> int64 {
|
||||||
|
return bux_abs_i64(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
func AbsF(f: float64) -> float64 {
|
||||||
|
return bux_abs_f64(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
func Min(a: int64, b: int64) -> int64 {
|
||||||
|
return bux_min_i64(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
func Max(a: int64, b: int64) -> int64 {
|
||||||
|
return bux_max_i64(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
func MinF(a: float64, b: float64) -> float64 {
|
||||||
|
return bux_min_f64(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
func MaxF(a: float64, b: float64) -> float64 {
|
||||||
|
return bux_max_f64(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -520,6 +520,18 @@ char* bux_path_ext(const char* path) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Math functions — wrap C math.h */
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
double bux_sqrt(double x) { return sqrt(x); }
|
||||||
|
double bux_pow(double x, double y) { return pow(x, y); }
|
||||||
|
int64_t bux_abs_i64(int64_t x) { return x < 0 ? -x : x; }
|
||||||
|
double bux_abs_f64(double x) { return x < 0 ? -x : x; }
|
||||||
|
int64_t bux_min_i64(int64_t a, int64_t b) { return a < b ? a : b; }
|
||||||
|
int64_t bux_max_i64(int64_t a, int64_t b) { return a > b ? a : b; }
|
||||||
|
double bux_min_f64(double a, double b) { return a < b ? a : b; }
|
||||||
|
double bux_max_f64(double a, double b) { return a > b ? a : b; }
|
||||||
|
|
||||||
/* Hash function (djb2) over raw bytes — for generic key types */
|
/* Hash function (djb2) over raw bytes — for generic key types */
|
||||||
unsigned int bux_hash_bytes(const void* ptr, size_t size) {
|
unsigned int bux_hash_bytes(const void* ptr, size_t size) {
|
||||||
if (!ptr) return 0;
|
if (!ptr) return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user