HaxeFlixel / HaxeFlixel/flixel
Float rounding issue at updateFilledBar() in FlxBar
Nobody has claimed this yet.
- Dominant language
- Haxe
- Stars
- 2.2k
- Forks
- 522
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
In updateFilledBar() function, where it's calculating how much division a bar should draw
this line
var interval:Float = Math.round(Std.int(fraction * maxScale / scaleInterval) * scaleInterval);
should just be
var interval:Float = Math.round(fraction * maxScale / scaleInterval * scaleInterval);
or
var interval:Float = Math.round(Math.round(fraction * maxScale / scaleInterval) * scaleInterval);
The issue is in certain bar size and range (for example, bar is 490 pixel long, range is 0 to 1, and current var value is 1)
the value of interval is wrong due to floating point error (in this example, you got 485 instead of correct value 490)
the problem is when haxe calculating fraction * maxScale / scaleInterval
(in this case, it will be 1*490/4.9 , the correct value should be 100), the actual value it calculated is 99.99999999999999
and this cause bar short 1 division with Std.int involved.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate updateFilledBar() in FlxBar and reproduce the reported 490-pixel bar, 0–1 range, and value 1 case. Check the computed interval and verify that the change prevents the bar from ending at 485 instead of 490; the issue does not name a test file.
Written by the indexing model from the issue text.
Assessment
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100