xsharp.eu • If someone can explain it to me?
Page 1 of 3

If someone can explain it to me?

Posted: Fri Mar 22, 2019 7:47 am
by softdevo@tiscali.it
Look at the attached image: the same code in another application works perfectly, but here .... I just don't understand.
Danilo

If someone can explain it to me?

Posted: Fri Mar 22, 2019 8:13 am
by SHirsch
Hi Danilo,

try using System.Decimal instead of System.Double.

see: https://www.xsharp.eu/forum/public-vo-v ... cimal#7418

Regards,
Stefan

If someone can explain it to me?

Posted: Fri Mar 22, 2019 8:13 am
by FFF
Sorry, Danilo,
pls post bigger shots, this one is impossible to read.

Karl

If someone can explain it to me?

Posted: Fri Mar 22, 2019 9:24 am
by wriedmann
Hi Danilo,
this is how real8 and floats work, and it is that way also in VO.
Look at your SetFloatDelta() setting in both applications.
Wolfgang

If someone can explain it to me?

Posted: Fri Mar 22, 2019 11:39 am
by TerryB1
Danilo
The reason for this boils down to rounding errors.

Computations in a digital computer are exact using a number base of 2.
Our understanding is based on a base of 10.

Any conversion will be slightly inaccurate.

To ensure total and absolute consistency in this process every calculation made must be rounded in the same way (up or down). Any compiler will do this in a consistent way.

The downside of this is that the rounding process takes time, and if we require total accuracy, must be done as part of each calculation. When there are thousands of such conversions/calculations to be done this mounts up.

As long as we are dealing with very small rounding errors we need not worry because they will never build up to such an extent as to have any noticeable effect on what we are trying to calculate.

For example, calculating an on-screen pixel position to 2 places of decimals would achieve little.

Floats are designed to calculate numerical results over a huge range, whilst not requiring the additional time-consuming overhead of base numbering scheme conversion.

Therefore, you should never use Floats in any situation where absolute comparisons/values may be required.
They do save time of course, when compared to decimal. It’s a case of “horses for courses”.

Terry
PS Having just read Wolfgang's reply I'm just guessing that SetFloatDelta() gives an accuracy limitation on Floats, allowing the compiler to do things to whatever accuracy is required.
So rather than saying never use Floats, I guess it should be "do not use floats unless SetFloatData() is set.
That is just a guess.

If someone can explain it to me?

Posted: Fri Mar 22, 2019 3:45 pm
by softdevo@tiscali.it
Thanks to all, but I don't understand why with any other value it gives a correct result and only 8.70 gives error, then multiplying by 100 should not generate any rounding.
Another thing I don't understand is why the same code in any other application works.
I will try your suggestions, but I'm not satisfied, because every calculation is therefore in danger.
Danilo

If someone can explain it to me?

Posted: Fri Mar 22, 2019 4:33 pm
by Chris
Hi Danilo,

Some decimal numbers can be represented better than others. For example, the decimal value 0.625 can be perfectly represented in binary accurately as 0.101, while 0.626 can only be represented in approximation.

The important question is, do you get a problem in your app while running it, or is it just the value you see in the debugger that you do not like? Because normally, when you actually print values to show to the user, you use some kind of rounding, which will eliminate that precision lost.

If someone can explain it to me?

Posted: Fri Mar 22, 2019 5:02 pm
by TerryB1
Hi Danilo

Unfortunately, as Karl said, I could not read your post properly.

I made an assumption that it was probably due to rounding errors. I should not have done this - there may be other factors at play here.

We need to see the full code properly.

Sorry if I've managed to steer this discussion in the wrong direction.

Terry

If someone can explain it to me?

Posted: Fri Mar 22, 2019 5:19 pm
by Chris
No worries Terry, I think both your and Karl's points were valid as well.

If someone can explain it to me?

Posted: Sat Mar 23, 2019 8:52 am
by TerryB1
Thanks Chris. It will be interesting to see what the problem turns out to be.

Terry