2 registered members (Akow, tomaslolo),
1,536
guests, and 12
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ifelse's strange perception of zero
#455947
11/04/15 00:20
11/04/15 00:20
|
Joined: Dec 2013
Posts: 568 Fuerth, DE
Sphin
OP
User
|
OP
User
Joined: Dec 2013
Posts: 568
Fuerth, DE
|
function main() {
var a = 1.0;
var b = ifelse(a > 0, a, 0);
printf("b = %.1f",b);
}
Result: b = 1.0
function main() {
var a = 0.9;
var b = ifelse(a > 0, a, 0);
printf("b = %.1f",b);
}
Result: b = 0.0 means: 0.9 > 0 is not true. I spent hours to search for an error in my script ...
|
|
|
Re: ifelse's strange perception of zero
[Re: Florastamine]
#455952
11/04/15 09:39
11/04/15 09:39
|
Joined: Dec 2013
Posts: 568 Fuerth, DE
Sphin
OP
User
|
OP
User
Joined: Dec 2013
Posts: 568
Fuerth, DE
|
From the manual (printf/print/msg): For printing float variables with the %f placeholder, typecast them to (var). For my variables are already declared as var I did not typecast them. What's right now?
|
|
|
Re: ifelse's strange perception of zero
[Re: jcl]
#456021
11/05/15 23:43
11/05/15 23:43
|
Joined: Dec 2013
Posts: 568 Fuerth, DE
Sphin
OP
User
|
OP
User
Joined: Dec 2013
Posts: 568
Fuerth, DE
|
Strict distinction of the different types of variables and the consequences thereof are quite new for me switching from Perl to C.
Returns:
x when c is true, otherwise y.
Remarks:
The returned variable type depends on the type of the arguments;[...]
Of course it's objectively right, but I thought if x is a var and y is an int then if c is true the returned variable is a var, otherwise it is an int. I never have guessed that the arguments themselves have been touched for conversion to either int or var.
|
|
|
|