Place value jumps wildly! Possible bug

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Place value jumps wildly! Possible bug

#1 Post by lsf22 »

Renpy 8.03.22090809 (Python 3) (Linux)

Is it only occurring with the python 3 versions because this persisted with previous python 3 versions of Renpy? Whenever a number vaule gets added after a few times when it comes to decimals it jumps way up to a point where it should not.

For example on my test. I added a value of 0.4 a couple of times (3 times) till it created that anomaly

As you can see from the image that is attached. In the meantime how do I fix this?
Attachments
place value jumps up
place value jumps up

Mihara
Regular
Posts: 119
Joined: Thu Mar 11, 2010 2:52 pm
Contact:

Re: Place value jumps wildly! Possible bug

#2 Post by Mihara »

This is actually correct, funny as it sounds. See https://docs.python.org/3.9/tutorial/floatingpoint.html for a deeper discussion of the reasons, but it has to do with how floating point numbers are stored internally.

Code: Select all

$ python
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.4 + 0.4 + 0.4
1.2000000000000002
>>>
$ python2
Python 2.7.18 (default, Jul  1 2022, 12:27:04)
[GCC 9.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 0.4 + 0.4 + 0.4
1.2000000000000002
I do wonder why the 2.7-based versions of RenPy don't do that, actually, but the correct solution is to limit the number of digits on display anyway.

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Place value jumps wildly! Possible bug

#3 Post by lsf22 »

What can I do to prevent that from happening. It really screws up with how stats look in the renpy project I'm working on.
Does anyone have a solution?

Mihara
Regular
Posts: 119
Joined: Thu Mar 11, 2010 2:52 pm
Contact:

Re: Place value jumps wildly! Possible bug

#4 Post by Mihara »

Just add a format specifier when actually displaying the number:

Code: Select all

$ f = 0.4 + 0.4 + 0.4
"This line limits the [f:.2] to two digits after the decimal."
See https://peps.python.org/pep-3101/#format-specifiers for details. Or https://sahiljain444.medium.com/format- ... 1df860a6a4 for a more readable explanation.

User avatar
lsf22
Regular
Posts: 139
Joined: Wed Feb 23, 2022 9:43 pm
Contact:

Re: Place value jumps wildly! Possible bug

#5 Post by lsf22 »

I added that to one of my stats and it resulted in the following error: "Precision not allowed in integer format specifier"

example:

Code: Select all

frame:
        xpos 200
        ypos 20
        vbox:
            spacing 5
            text "Affection  [affection_g1:.2]" size 45 color "000000"

Mihara
Regular
Posts: 119
Joined: Thu Mar 11, 2010 2:52 pm
Contact:

Re: Place value jumps wildly! Possible bug

#6 Post by Mihara »

You were trying to print an integer number as if it had decimals. Which is bogus so it's complaining. You can force it anyway: Replace ":.2" with ":.2f" and it will convert integers to float before trying to print them.

Post Reply

Who is online

Users browsing this forum: No registered users