From 326dcd6f4a26256d8ed346dd789ea082d34db260 Mon Sep 17 00:00:00 2001 From: Leonardo Araujo Date: Sat, 4 Jan 2025 04:43:15 -0300 Subject: [PATCH] fix: output float double formatting --- ast.c | 31 +++---------------------------- examples/circle_area.brainrot | 2 +- tests/expected_results.json | 2 +- 3 files changed, 5 insertions(+), 30 deletions(-) diff --git a/ast.c b/ast.c index fbda180..b4d0101 100644 --- a/ast.c +++ b/ast.c @@ -1091,18 +1091,7 @@ void execute_yapping_call(ArgumentList *args) if (is_float_expression(expr)) { float val = evaluate_expression_float(expr); - if (strstr(formatNode->data.name, "%f") != NULL) - { - yapping(formatNode->data.name, val); // Use provided format - } - else if (strstr(formatNode->data.name, "%.") != NULL) - { - yapping(formatNode->data.name, val); // Use provided precision - } - else - { - yapping("%.6f", val); // Force exactly 6 decimal places - } + yapping(formatNode->data.name, val); return; } @@ -1215,28 +1204,14 @@ void execute_yappin_call(ArgumentList *args) if (is_float_expression(expr)) { float val = evaluate_expression_float(expr); - if (strstr(formatNode->data.name, "%f") != NULL) - { - yappin("%.6f", val); // Force 6 decimal places - } - else - { - yappin("%.6f", val); - } + yappin(formatNode->data.name, val); return; } if (is_double_expression(expr)) { double val = evaluate_expression_double(expr); - if (strstr(formatNode->data.name, "%lf") != NULL) - { - yappin("%.6lf", val); // Force 6 decimal places - } - else - { - yappin("%.6lf", val); - } + yappin(formatNode->data.name, val); return; } diff --git a/examples/circle_area.brainrot b/examples/circle_area.brainrot index 272c067..aecf545 100644 --- a/examples/circle_area.brainrot +++ b/examples/circle_area.brainrot @@ -3,6 +3,6 @@ skibidi main { chad pi = 3.141592; chad r = 5.0; chad area = pi * r * r; // Area of a circle - yappin("%f\n", area); + yappin("%.3f\n", area); bussin 0; } \ No newline at end of file diff --git a/tests/expected_results.json b/tests/expected_results.json index 1340314..814e8ff 100644 --- a/tests/expected_results.json +++ b/tests/expected_results.json @@ -7,7 +7,7 @@ "float.brainrot": "3.141592\n", "modulo.brainrot": "2\n", "switch_case.brainrot": "You chose 2, gigachad move!\n", - "circle_area.brainrot": "78.539800\n", + "circle_area.brainrot": "78.540\n", "circle_area_double.brainrot": "78.539800\n", "for_loop.brainrot": "Skibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\n", "output_error.brainrot": "you sussy baka!",