Expect retrieved value to be the same as assigned value #235

Open
opened 2020-12-29 05:01:31 +00:00 by khiav223577 · 3 comments
khiav223577 commented 2020-12-29 05:01:31 +00:00 (Migrated from github.com)

Example:

sprite = Sprite.new
sprite.zoom_x = 0.9
p sprite.zoom_x

In original RPG Maker XP engine, it prints 0.9
But it prints 0.8999999761581421 in mkxp (OSX binary)

Example: ```rb sprite = Sprite.new sprite.zoom_x = 0.9 p sprite.zoom_x ``` In original RPG Maker XP engine, it prints 0.9 But it prints 0.8999999761581421 in mkxp (OSX binary)
cremno commented 2020-12-29 08:56:59 +00:00 (Migrated from github.com)

mkxp uses the single-precision floating-point format for this and similar attributes while RGSS uses double-precision.

However even if it would be changed to double-precision you would still be able to find differences in very few cases. 1.8.1 is ancient and the code to convert between floating-point numbers and strings contained some bugs.

mkxp uses the single-precision floating-point format for this and similar attributes while RGSS uses double-precision. However even if it would be changed to double-precision you would still be able to find differences in very few cases. 1.8.1 is ancient and the code to convert between floating-point numbers and strings contained some bugs.
khiav223577 commented 2020-12-29 09:46:58 +00:00 (Migrated from github.com)

Maybe a wrapper class is one possible solution?

  1. Rename the Sprite class implemented by mkxp as MkxpSprite
  2. Define new Sprite class that inherits from MkxpSprite
  3. Override zoom_x and zoom_x= method.
class Sprite < MkxpSprite
  attr_reader :zoom_x

  def zoom_x=(val)
    @zoom_x = val
    super
  end
end

It will be nice if mkxp can implement it. Make mkxp behave more consistent with original engine.


The following is a surprising behavior I found in current implementation:

# let (xxxxx / yyyyy.to_f) to be 0.9
sprite.zoom_x = xxxxx / yyyyy.to_f 

# ...
# ...

# sprite.zoom_x is 0.8999 here and fail to enter the if-condition since 0.8999 is not larger than or equals to 0.9
if sprite.zoom_x >= 0.9 
  #  ...
  #  ...
end
Maybe a wrapper class is one possible solution? 1. Rename the `Sprite` class implemented by mkxp as `MkxpSprite` 2. Define new `Sprite` class that inherits from `MkxpSprite` 3. Override `zoom_x` and `zoom_x=` method. ```rb class Sprite < MkxpSprite attr_reader :zoom_x def zoom_x=(val) @zoom_x = val super end end ``` It will be nice if mkxp can implement it. Make mkxp behave more consistent with original engine. --- The following is a surprising behavior I found in current implementation: ```rb # let (xxxxx / yyyyy.to_f) to be 0.9 sprite.zoom_x = xxxxx / yyyyy.to_f # ... # ... # sprite.zoom_x is 0.8999 here and fail to enter the if-condition since 0.8999 is not larger than or equals to 0.9 if sprite.zoom_x >= 0.9 # ... # ... end ```
Ancurio commented 2021-11-07 21:03:09 +00:00 (Migrated from github.com)

I am curious what exact in-game issues this inaccuracy is causing.

I am curious what exact in-game issues this inaccuracy is causing.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: MapleShrine/mkxp#235
No description provided.