If someone can explain it to me?

We encourage new members to introduce themselves here. Get to know one another and share your interests.
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

If someone can explain it to me?

Post 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
Attachments
Immagine.jpg
Immagine.jpg (83.99 KiB) Viewed 1041 times
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

If someone can explain it to me?

Post 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
FFF
Posts: 1590
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

If someone can explain it to me?

Post by FFF »

Sorry, Danilo,
pls post bigger shots, this one is impossible to read.

Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3784
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

If someone can explain it to me?

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

If someone can explain it to me?

Post 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.
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

If someone can explain it to me?

Post 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
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

If someone can explain it to me?

Post 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.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

If someone can explain it to me?

Post 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
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

If someone can explain it to me?

Post by Chris »

No worries Terry, I think both your and Karl's points were valid as well.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
TerryB1
Posts: 306
Joined: Wed Jan 03, 2018 11:58 am

If someone can explain it to me?

Post by TerryB1 »

Thanks Chris. It will be interesting to see what the problem turns out to be.

Terry
Post Reply