PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → SIN(360) <>0  .... wrong value ???
SIN(360) <>0 .... wrong value ???
Débuté par BALTASAR, 03 jan. 2020 12:05 - 4 réponses
Membre enregistré
52 messages
Popularité : +3 (3 votes)
Posté le 03 janvier 2020 - 12:05
I'm using many trigonometric formulas, then I see that windev fails with a few of them, for example

trace(SIN(360))

returns: -0.0000000000000002449293598295

I found that sin(modulo(myangle,360)) works fine but I don't trust in every other calculations.
Posté le 03 janvier 2020 - 15:58
I haven't tested, but it looks like the usual "Real imprecision" problem.

If I'm right, do
MyNumeric is numeric = 360
trace(sin(mynumeric))

What is happening in my opinion is that the compiler is interpreting 360 as real, as you do not type the value. This is done this way for historical reasons (currenty and high precision numeric did not exist in old versions of the compiler, and changing this behavior would break existing code).

So any explicit number used in an expression/calculation is real by default... And reals, by construction and in ANY language, are not able to store every possible value, hence this kind of problem.

So the function is not in question.
Membre enregistré
52 messages
Popularité : +3 (3 votes)
Posté le 08 janvier 2020 - 10:39
MyNumeric is numeric = 360
Trace(Sin(mynumeric))


result: -0.0000000000000002449293598295

still wrong
Posté le 22 janvier 2020 - 14:03
moResultaat est un monétaire = Sin(360)
Trace(moResultaat)
Membre enregistré
52 messages
Popularité : +3 (3 votes)
Posté le 22 janvier 2020 - 15:32
Thanks, Tim.

What I can't understand is that Windev says:

Currency: recommended type for the calculations performed on real values that require an absolute precision for the decimals, as currency values for example.
A currency manages 24 significant digits (up to 18 digits for the integer part and up to 6 digits for the decimal part). The precision is precise to 6 decimals.
For more details about the currencies.
Example: MyCurrency is currency

Numeric: recommended type for the calculations on real values that required an absolute precision for the decimals.
A numeric manages 38 significant digits (up to 32 digits for the integer part and up to 6 digits for the decimal part). The precision is precise to 6 decimals.
For more details about the numerics.
Example: MyCurrency is numeric