Anuken / Mindustry-Suggestions

Repository for Mindustry suggestions and feedback
131 stars 58 forks source link

Logic: rounding numbers in print and format #5319

Open cardillan opened 1 week ago

cardillan commented 1 week ago

Describe what you would like changed, and why.

When using the print and format instructions, values slightly above an integer value are rounded to the integer value, but values slightly below aren't:

print 1.000001
print 0.999999
print 0.9999999

produces

1
0.999999
0.9999999

on output.

I guess it is an accident - I can't figure out a reason why values should only be rounded down.

Describe the changes you want to propose. Include possible alternatives.

I propose to change (long)value.numval in PrintI.run and FormatI.run methods to (long)(value.numval+0.5), so that the value to be printed is rounded to the nearest integer for comparison/printing. (Edited to add: the same change should be also done on the Vars screen for consistency.)

(I can do a PR if it is easier for you.)

Accollide commented 1 week ago

this seems like a bug. should submit to bug report. I am curious to know how you found this out though

cardillan commented 6 days ago

this seems like a bug. should submit to bug report.

I think I'll do the PR and see whether it gets accepted.

I am curious to know how you found this out though

I'm developing Mindcode,a high-level language for Mindustry Logic. It contains a Mindustry processor emulator, so I sometimes get into quite a lot of detail... :)