[spam] Language learning: Julia
Karl Semich
0xloem at gmail.com
Sun Apr 24 05:35:44 PDT 2022
Chapter 5: structural numbers
- the imaginary number is the constant "im"
julia> (1 - 3im) / (2 + 2im)
-0.5 - 1.0im
julia> real(1 + 2im) # real part of z
1
julia> imag(1 + 2im) # imaginary part of z
2
julia> conj(1 + 2im) # complex conjugate of z
1 - 2im
julia> abs(1 + 2im) # absolute value of z
2.23606797749979
julia> abs2(1 + 2im) # squared absolute value
5
julia> angle(1 + 2im) # phase angle in radians
1.
julia> sqrt(-1)
ERROR: DomainError with -1.0:
sqrt will only return a complex result if called with a complex argument.
Try sqrt(Complex(x)).
Stacktrace:
[...]
julia> sqrt(-1 + 0im)
0.0 + 1.0im
constructing a complex number at runtime:
julia> a = 1; b = 2; complex(a, b)
1 + 2im
Rationals are constructed using the // operator:
julia> 2//3
2//3
julia> -4//-12
1//3
julia> numerator(2//3)
2
julia> denominator(2//3)
3
julia> float(3//4)
0.75
julia> x = -3//0
-1//0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/html
Size: 2520 bytes
Desc: not available
URL: <https://lists.cpunks.org/pipermail/cypherpunks/attachments/20220424/3a7459b0/attachment.txt>
More information about the cypherpunks
mailing list