From d5e63ec14309758dc40d77b202d411e3f61cd8c0 Mon Sep 17 00:00:00 2001 From: ylluminate Date: Fri, 20 Feb 2026 00:40:50 -0500 Subject: [PATCH] handle round() with ndigits argument Python's round(x, ndigits) was dropping the second argument, producing math.round(x) instead of preserving decimal-place precision. round(3.14159, 2) produced 3.0 instead of 3.14. Uses math.round_sig(x, ndigits) for the two-argument form. Single-argument round(x) is unchanged. - visit_round() in plugins.v: dispatch on args.len for ndigits - 1 test expected output updated (abs_round) All 108 tests pass. --- plugins.v | 3 +++ tests/expected/abs_round.v | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins.v b/plugins.v index 1a39fe5..713540b 100644 --- a/plugins.v +++ b/plugins.v @@ -291,6 +291,9 @@ fn visit_abs(args []string) (string, bool, string) { // Handle round() call fn visit_round(args []string) (string, bool, string) { + if args.len >= 2 { + return 'math.round_sig(${args[0]}, ${args[1]})', true, 'math' + } return 'math.round(${args[0]})', true, 'math' } diff --git a/tests/expected/abs_round.v b/tests/expected/abs_round.v index 749afe9..f085a79 100644 --- a/tests/expected/abs_round.v +++ b/tests/expected/abs_round.v @@ -10,8 +10,8 @@ fn main_func() { println((math.round(3.7)).str()) println((math.round(3.2)).str()) println((math.round(3.5)).str()) - println((math.round(3.1415900000000003)).str()) - println((math.round(2.71828)).str()) + println((math.round_sig(3.1415900000000003, 2)).str()) + println((math.round_sig(2.71828, 3)).str()) println((math.abs(-3.14)).str()) }