Page 1 of 1
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:06 am
by softdevo@tiscali.it
LOCAL nDec AS System.Double oppure AS FLOAT oppure AS System.Decimal
nDec := (56/39)
torna sempre 1 e non 1,43.... grazie
Danilo
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:39 am
by Juraj
maybe my attempt will help
LOCAL nDec as Decimal
nDec:=(57./36.)
return 1.46
Juraj
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:44 am
by FFF
Works, if you write either number with a ".0"
But this is certainly a bug
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:48 am
by wriedmann
Ciao Danilo,
Juraj is right.
"57" e "39" sono considerati tipo integer, perciò il risultato sarà int, se non imposti /vo12 ("Integer divisions return float").
Altra possibilità:
Code: Select all
nDec := (56d/39d)
nDec := (56m/39m)
Vedi:
https://docs.xsharp.it/doku.php?id=literals
Saluti
Wolfgang
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:52 am
by Juraj
just one with a dot (57./39) or (57/39.) return 1.46
Cosa sbaglio?
Posted: Wed Aug 21, 2019 8:58 am
by wriedmann
Hi Karl,
this is not a bug. If the /vo12 compiler option is not selected, every division by integers return an integer.
VO behaves the same.
Wolfgang
Cosa sbaglio?
Posted: Wed Aug 21, 2019 9:33 am
by FFF
Wolfgang,
i see. Hadn't thought that this may be the case even in core
And, as i just found out, it does not. Setting /vo12 makes the compile fail.
For reference tried in c#, the results are the same. So, it's one of these pitfalls, one has to keep in mind....
I think, i'd prefer the opposite behaviour as default, as i can't think of a lot of showcases, where one works on literal ints and wants to get the truncated result. But that's just me
Cosa sbaglio?
Posted: Wed Aug 21, 2019 10:02 am
by Karl-Heinz
funny, i firstly thought my cpu is defect, until i´ve noticed that there are different division that cause of course different results
(56/39)
(57./36.)
(57./39)
here´s another float result option
? (decimal) 56/39
? (double) 56/39
? (FLOAT) 56/39
regards
Karl-Heinz
Cosa sbaglio?
Posted: Wed Aug 21, 2019 10:07 am
by softdevo@tiscali.it
Thanks to all
Danilo
Cosa sbaglio?
Posted: Wed Aug 21, 2019 11:49 am
by wriedmann
Hi Karl,
And, as i just found out, it does not. Setting /vo12 makes the compile fail.
For reference tried in c#, the results are the same. So, it's one of these pitfalls, one has to keep in mind....
I think, i'd prefer the opposite behaviour as default, as i can't think of a lot of showcases, where one works on literal ints and wants to get the truncated result. But that's just me
so the behaviour of C# is the same as VO and X#.... I would also prefer to have the same as default - had similar problems several times in my VO applications, and therefore I'm always writing numeric literals with decimal point and 0 when dividing, and casting integer variables to float.
But compatibility is important, and changing it would break really a lot of code.
And I can understand why /vo12 makes the compile fail on Core dialect: there is no float datatype.
Wolfgang