Wednesday, 3 February 2016

Julia: Comparison operators Vs Special float values

a.   Positive zero is equal to negative zero, but not greater, less than negative zero.
b.   Inf is equal to itself and greater than everything, except NaN
c.    -Inf is equal to itself and less then everything, except NaN.

d.   NaN is not equal to, not less than, and not greater than anything, including itself.

julia> 0.0==-0.0
true

julia> 0.0>-0.0
false

julia> 0.0<-0.0
false

julia> NaN==NaN
false

julia> NaN>=NaN
false

julia> NaN<=NaN
false

julia> Inf==Inf
true

julia> Inf==-Inf
false

julia> -Inf==-Inf
true

julia> Inf>-Inf
true

julia> Inf<-Inf
false

julia> Inf>NaN
false

julia> Inf<NaN
false

julia> Inf>100000
true

julia> -Inf<-1000000
true

julia> -Inf>-1000000
false





Previous                                                 Next                                                 Home

Monday, 1 February 2016

Julia: Comparison operators

Julia supports following comparison operators. Comparison operators determine if one operand is greater than, less than, equal to, or not equal to another operand. Comparison operator takes two operands and return true, if the condition evaluates to true, otherwise return false.

Operator
Description
==
equal to
!=
not equal to
> 
greater than
>=
greater than or equal to
< 
less than
<=
less than or equal to



julia> a=10;b=20;

julia> a>b
false

julia> a<b
true

julia> a>=b
false

julia> a<=b
true

julia> !(a>b)
true



Previous                                                 Next                                                 Home

Julia: Assignment operator


Assignment operator (=) is used to assign a value to a variable.
julia> a=10;

julia> a
10

julia> name="Hari Krishna";

julia> name
"Hari Krishna"

Julia support compound assignment also.
Compound assignment operator
Example
Description
+=
a+=10
a=a+10
-+
a-=10
a=a-10
*=
A*=10
a=a*10
/=
a/=10
a=a/10
\=
a\=10
a=a\10
^=
a^=10
a=a^10
%=
a%=10
a=a%10
&=
a&=b
a=a&b
|=
a|=b
a=a|b
$=
a$=b
a=a$b
>>>=
a>>>=10
a=a>>>10
>>=
a>>=10
a=a>>10
<<=
a<<=10
a=a<<10


julia> a=10;b=10;c=10;d=10;

julia> a+=10;b-=10;c*=10;d/=10;

julia> a
20

julia> b
0

julia> c
100

julia> d
1.0






Previous                                                 Next                                                 Home