752
752
@test Complex(1,2) + 1//2 == Complex(3//2,2//1)
753
753
@test Complex(1,2) + 1//2 * 0.5 == Complex(1.25,2.0)
754
754
@test (Complex(1,2) + 1//2) * 0.5 == Complex(0.75,1.0)
755
@test (Complex(1,2)/Complex(2.5,3.0))*Complex(2.5,3.0) == Complex(1,2)
755
@test_approx_eq (Complex(1,2)/Complex(2.5,3.0))*Complex(2.5,3.0) Complex(1,2)
756
756
@test 0.7 < real(sqrt(Complex(0,1))) < 0.707107
758
758
for T in {Int8,Int16,Int32,Int64,Int128}
1511
1511
# overflow in rational comparison
1512
1512
@test 3//2 < typemax(Int)
1513
1513
@test 3//2 <= typemax(Int)
1515
# check gcd and related functions against GMP
1516
for i = -20:20, j = -20:20
1522
@test d == gcd(ib,jb)
1523
@test lcm(i,j) == lcm(ib,jb)
1524
@test gcdx(i,j) == gcdx(ib,jb)
1526
@test_throws invmod(i,j)
1527
@test_throws invmod(ib,jb)
1530
@test n == invmod(ib,jb)
1531
@test mod(n*i,j) == mod(1,j)
1535
# check powermod function against GMP
1536
for i = -10:10, p = 0:5, m = -10:10
1538
@test powermod(i,p,m) == powermod(i,p,big(m)) == powermod(big(i),big(p),big(m))
1539
@test mod(i^p,m) == powermod(i,p,m) == mod(big(i)^p,big(m))
1543
# with m==1 should give 0
1544
@test powermod(1,0,1) == 0
1545
@test powermod(big(1),0,1) == 0
1546
@test powermod(1,0,-1) == 0
1547
@test powermod(big(1),0,-1) == 0
1548
# divide by zero error
1549
@test_throws powermod(1,0,0)
1550
@test_throws powermod(big(1),0,0)
1551
# negative power domain error
1552
@test_throws powermod(1,-2,1)
1553
@test_throws powermod(big(1),-2,1)
1555
# prevpow2/nextpow2:
1556
@test nextpow2(0) == prevpow2(0) == 0
1558
@test nextpow2(i) == prevpow2(i) == i
1560
@test nextpow2(56789) == -nextpow2(-56789) == 65536
1561
@test prevpow2(56789) == -prevpow2(-56789) == 32768
1563
@test nextpow2(i) == nextpow2(big(i))
1564
@test prevpow2(i) == prevpow2(big(i))