MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / oracle_round

Function oracle_round

graphlite/src/functions/numeric_functions.rs:104–122  ·  view source on GitHub ↗

Oracle-compatible ROUND function implementation ROUND(n, integer) follows Oracle's rounding rules: - If n is 0, always returns 0 - For negative n: ROUND(n, integer) = -ROUND(-n, integer) - Uses "round half away from zero" behavior

(n: f64, decimal_places: i32)

Source from the content-addressed store, hash-verified

102/// - For negative n: ROUND(n, integer) = -ROUND(-n, integer)
103/// - Uses "round half away from zero" behavior
104fn oracle_round(n: f64, decimal_places: i32) -> f64 {
105 if n == 0.0 {
106 return 0.0;
107 }
108
109 // Handle negative numbers: ROUND(n, integer) = -ROUND(-n, integer)
110 if n < 0.0 {
111 return -oracle_round(-n, decimal_places);
112 }
113
114 // Calculate the multiplier for the decimal places
115 let multiplier = 10.0_f64.powi(decimal_places);
116
117 // Apply Oracle's rounding: ROUND(n, integer) = FLOOR(n * 10^integer + 0.5) / 10^integer
118 let scaled = n * multiplier + 0.5;
119 let floored = scaled.floor();
120
121 floored / multiplier
122}

Callers 1

executeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected