From 12a7756588a20f1351e6976f0c009de5992514a9 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 21 Jun 2026 16:48:03 +0900 Subject: feat(php-shim): implement round() shim Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/src/math.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) (limited to 'crates/shirabe-php-shim/src') diff --git a/crates/shirabe-php-shim/src/math.rs b/crates/shirabe-php-shim/src/math.rs index fffe2d6..ee9a76d 100644 --- a/crates/shirabe-php-shim/src/math.rs +++ b/crates/shirabe-php-shim/src/math.rs @@ -1,33 +1,30 @@ -pub fn max_i64(_a: i64, _b: i64) -> i64 { - _a.max(_b) +pub fn max(a: i64, b: i64) -> i64 { + a.max(b) } -pub fn max(_a: i64, _b: i64) -> i64 { - _a.max(_b) +pub fn min(a: i64, b: i64) -> i64 { + a.min(b) } -pub fn min(_a: i64, _b: i64) -> i64 { - _a.min(_b) +pub fn abs(v: i64) -> i64 { + v.abs() } -pub fn abs(_value: i64) -> i64 { - _value.abs() -} - -pub fn floor(_value: f64) -> f64 { - _value.floor() +pub fn floor(v: f64) -> f64 { + v.floor() } pub fn ceil(v: f64) -> f64 { v.ceil() } -pub fn round(_value: f64, _precision: i64) -> f64 { - todo!() +pub fn round(v: f64, precision: i64) -> f64 { + // PHP's default mode is PHP_ROUND_HALF_UP (round half away from zero), + // which matches Rust's f64::round. + let factor = 10f64.powi(precision as i32); + (v * factor).round() / factor } pub fn intdiv(a: i64, b: i64) -> i64 { - // PHP intdiv() throws DivisionByZeroError on a zero divisor and ArithmeticError - // for PHP_INT_MIN / -1; Rust's `/` likewise panics in both cases. a / b } -- cgit v1.3.1