Skip to content

Commit

Permalink
Merge pull request #38 from Brainrotlang/fix/output-float-double-form…
Browse files Browse the repository at this point in the history
…atting

fix: output float double formatting
  • Loading branch information
araujo88 authored Jan 4, 2025
2 parents 2170168 + 326dcd6 commit da2d2a7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 30 deletions.
31 changes: 3 additions & 28 deletions ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/circle_area.brainrot
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion tests/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down

0 comments on commit da2d2a7

Please sign in to comment.