Skip to content

Commit da2d2a7

Browse files
authored
Merge pull request #38 from Brainrotlang/fix/output-float-double-formatting
fix: output float double formatting
2 parents 2170168 + 326dcd6 commit da2d2a7

File tree

3 files changed

+5
-30
lines changed

3 files changed

+5
-30
lines changed

ast.c

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,18 +1091,7 @@ void execute_yapping_call(ArgumentList *args)
10911091
if (is_float_expression(expr))
10921092
{
10931093
float val = evaluate_expression_float(expr);
1094-
if (strstr(formatNode->data.name, "%f") != NULL)
1095-
{
1096-
yapping(formatNode->data.name, val); // Use provided format
1097-
}
1098-
else if (strstr(formatNode->data.name, "%.") != NULL)
1099-
{
1100-
yapping(formatNode->data.name, val); // Use provided precision
1101-
}
1102-
else
1103-
{
1104-
yapping("%.6f", val); // Force exactly 6 decimal places
1105-
}
1094+
yapping(formatNode->data.name, val);
11061095
return;
11071096
}
11081097

@@ -1215,28 +1204,14 @@ void execute_yappin_call(ArgumentList *args)
12151204
if (is_float_expression(expr))
12161205
{
12171206
float val = evaluate_expression_float(expr);
1218-
if (strstr(formatNode->data.name, "%f") != NULL)
1219-
{
1220-
yappin("%.6f", val); // Force 6 decimal places
1221-
}
1222-
else
1223-
{
1224-
yappin("%.6f", val);
1225-
}
1207+
yappin(formatNode->data.name, val);
12261208
return;
12271209
}
12281210

12291211
if (is_double_expression(expr))
12301212
{
12311213
double val = evaluate_expression_double(expr);
1232-
if (strstr(formatNode->data.name, "%lf") != NULL)
1233-
{
1234-
yappin("%.6lf", val); // Force 6 decimal places
1235-
}
1236-
else
1237-
{
1238-
yappin("%.6lf", val);
1239-
}
1214+
yappin(formatNode->data.name, val);
12401215
return;
12411216
}
12421217

examples/circle_area.brainrot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ skibidi main {
33
chad pi = 3.141592;
44
chad r = 5.0;
55
chad area = pi * r * r; // Area of a circle
6-
yappin("%f\n", area);
6+
yappin("%.3f\n", area);
77
bussin 0;
88
}

tests/expected_results.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"float.brainrot": "3.141592\n",
88
"modulo.brainrot": "2\n",
99
"switch_case.brainrot": "You chose 2, gigachad move!\n",
10-
"circle_area.brainrot": "78.539800\n",
10+
"circle_area.brainrot": "78.540\n",
1111
"circle_area_double.brainrot": "78.539800\n",
1212
"for_loop.brainrot": "Skibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\nSkibidi toilet\n",
1313
"output_error.brainrot": "you sussy baka!",

0 commit comments

Comments
 (0)