Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
khiav223577 opened this issue Dec 29, 2020 · 3 comments
Open

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

khiav223577 opened this issue Dec 29, 2020 · 3 comments

Comments

@khiav223577
Copy link

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)

@cremno
Copy link
Contributor

cremno commented Dec 29, 2020

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
Copy link
Author

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

@Ancurio
Copy link
Owner

Ancurio commented Nov 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants