Page 1 of 1

EOS question

Posted: Wed Feb 12, 2020 9:42 pm
by boundupone
Hi guys,

I have started working on Estim Experiment day 2

I have a small issue. I am using Lolol's method of controlling volume, but I am finding when I use var

volume = volume + 0.1

And use say <volume>

The numbers go strange.

For example I start at 40%, but quickly it has gone to something like 40.800000000002%

Can anyone tell me a way to solve this. I don't mind the actual vol being a random long number, but when the mistress is telling you the volume it should be a nice 40.80% for example

Cheers

Re: EOS question

Posted: Wed Feb 12, 2020 9:56 pm
by undeniable_denial

Code: Select all

volume.toFixed(1)
Rounds it to 1 decimal place even if it's zero (and also converts it to a string, e.g. "40.0")

Re: EOS question

Posted: Thu Feb 13, 2020 12:47 am
by kerkersklave
boundupone wrote: Wed Feb 12, 2020 9:42 pm For example I start at 40%, but quickly it has gone to something like 40.800000000002%
The reason for that is that Javascript uses binary floating point numbers to represent numbers.
You are using decimal floating point numbers.
A number like 0.1 to basis 10 cannot be represented in basis 2 with a finite number of digits.

If you use powers of 1/2 like 0.5, 0.25, 0.125, 0.0625 and sums of them, you will not have that problem.
(At least as long as the fractions will not get too small, but you will not need fractions that small).

If you do not want to limit yourself to such numbers, an other way is to use fractions to a denominator, e.g. x/1000.
Then you keep the numerator x as a variable and only compute the fraction whenever you need it.

Increasing and decreasing a floating point number over time with arbitrary fractions will always result in impressions accumulating. It is one of those things you should always avoid in programs.

Re: EOS question

Posted: Sat Feb 15, 2020 9:17 pm
by boundupone
undeniable_denial wrote: Wed Feb 12, 2020 9:56 pm

Code: Select all

volume.toFixed(1)
Rounds it to 1 decimal place even if it's zero (and also converts it to a string, e.g. "40.0")
Thanks, where do i input this code in EOS?

Re: EOS question

Posted: Sat Feb 15, 2020 9:25 pm
by boundupone
kerkersklave wrote: Thu Feb 13, 2020 12:47 am
boundupone wrote: Wed Feb 12, 2020 9:42 pm For example I start at 40%, but quickly it has gone to something like 40.800000000002%
The reason for that is that Javascript uses binary floating point numbers to represent numbers.
You are using decimal floating point numbers.
A number like 0.1 to basis 10 cannot be represented in basis 2 with a finite number of digits.

If you use powers of 1/2 like 0.5, 0.25, 0.125, 0.0625 and sums of them, you will not have that problem.
(At least as long as the fractions will not get too small, but you will not need fractions that small).


If you do not want to limit yourself to such numbers, an other way is to use fractions to a denominator, e.g. x/1000.
Then you keep the numerator x as a variable and only compute the fraction whenever you need it.

Increasing and decreasing a floating point number over time with arbitrary fractions will always result in impressions accumulating. It is one of those things you should always avoid in programs.
Thanks, that does work, so is a fairly easy workaround

Re: EOS question

Posted: Sat Feb 15, 2020 10:36 pm
by undeniable_denial
boundupone wrote: Sat Feb 15, 2020 9:17 pm
undeniable_denial wrote: Wed Feb 12, 2020 9:56 pm

Code: Select all

volume.toFixed(1)
Rounds it to 1 decimal place even if it's zero (and also converts it to a string, e.g. "40.0")
Thanks, where do i input this code in EOS?
In the Say-action. It doesn't modify the volume variable. It's just formatting.