1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

// TODO : port to Rust type : http://doc.rust-lang.org/num/complex/struct.Complex.html

use std::fmt::{Formatter, Debug};
use std::fmt;
use std::default::Default;
use ffi;

#[doc(hidden)]
pub trait CFFI<T> {
    fn wrap(s: T) -> Self;
    fn unwrap(self) -> T;
}

#[doc(hidden)]
pub trait FFFI<T> {
    fn wrap(self) -> T;
    fn unwrap(t: T) -> Self;
}

#[repr(C)]
#[derive(Copy, PartialEq)]
pub struct ComplexF64 {
    pub dat: [f64; 2]
}

impl ComplexF64 {
    /// This function uses the rectangular Cartesian components (x,y) to return the complex number
    /// z = x + i y.
    pub fn rect(x: f64, y: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_rect(x, y).wrap() }
    }

    /// This function returns the complex number z = r \exp(i \theta) = r (\cos(\theta) + i
    /// \sin(\theta)) from the polar representation (r,theta).
    pub fn polar(r: f64, theta: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_polar(r, theta).wrap() }
    }

    /// This function returns the argument of the complex number z, \arg(z), where -\pi < \arg(z)
    /// <= \pi.
    pub fn arg(&self) -> f64 {
        unsafe { ::ffi::gsl_complex_arg(self.unwrap()) }
    }

    /// This function returns the magnitude of the complex number z, |z|.
    pub fn abs(&self) -> f64 {
        unsafe { ::ffi::gsl_complex_abs(self.unwrap()) }
    }

    /// This function returns the squared magnitude of the complex number z, |z|^2.
    pub fn abs2(&self) -> f64 {
        unsafe { ::ffi::gsl_complex_abs2(self.unwrap()) }
    }

    /// This function returns the natural logarithm of the magnitude of the complex number z,
    /// \log|z|.
    ///
    /// It allows an accurate evaluation of \log|z| when |z| is close to one.
    ///
    /// The direct evaluation of log(gsl_complex_abs(z)) would lead to a loss of precision in this
    /// case.
    pub fn logabs(&self) -> f64 {
        unsafe { ::ffi::gsl_complex_logabs(self.unwrap()) }
    }

    /// This function returns the sum of the complex numbers a and b, z=a+b.
    pub fn add(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_add(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the difference of the complex numbers a and b, z=a-b.
    pub fn sub(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sub(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the product of the complex numbers a and b, z=ab.
    pub fn mul(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_mul(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the quotient of the complex numbers a and b, z=a/b.
    pub fn div(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_div(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the sum of the complex number a and the real number x, z=a+x.
    pub fn add_real(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_add_real(self.unwrap(), x).wrap() }
    }

    /// This function returns the difference of the complex number a and the real number x, z=a-x.
    pub fn sub_real(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sub_real(self.unwrap(), x).wrap() }
    }

    /// This function returns the product of the complex number a and the real number x, z=ax.
    pub fn mul_real(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_mul_real(self.unwrap(), x).wrap() }
    }

    /// This function returns the quotient of the complex number a and the real number x, z=a/x.
    pub fn div_real(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_div_real(self.unwrap(), x).wrap() }
    }
    
    /// This function returns the sum of the complex number a and the imaginary number iy, z=a+iy.
    pub fn add_imag(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_add_imag(self.unwrap(), x).wrap() }
    }

    /// This function returns the difference of the complex number a and the imaginary number iy,
    /// z=a-iy.
    pub fn sub_imag(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sub_imag(self.unwrap(), x).wrap() }
    }

    /// This function returns the product of the complex number a and the imaginary number iy,
    /// z=a*(iy).
    pub fn mul_imag(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_mul_imag(self.unwrap(), x).wrap() }
    }

    /// This function returns the quotient of the complex number a and the imaginary number iy,
    /// z=a/(iy).
    pub fn div_imag(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_div_imag(self.unwrap(), x).wrap() }
    }

    /// This function returns the complex conjugate of the complex number z, z^* = x - i y.
    pub fn conjugate(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_conjugate(self.unwrap()).wrap() }
    }

    /// This function returns the inverse, or reciprocal, of the complex number z, 1/z = (x - i y)/
    /// (x^2 + y^2).
    pub fn inverse(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_inverse(self.unwrap()).wrap() }
    }

    /// This function returns the negative of the complex number z, -z = (-x) + i(-y).
    pub fn negative(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_negative(self.unwrap()).wrap() }
    }

    /// This function returns the square root of the complex number z, \sqrt z.
    ///
    /// The branch cut is the negative real axis. The result always lies in the right half of the 
    /// omplex plane.
    pub fn sqrt(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sqrt(self.unwrap()).wrap() }
    }

    /// This function returns the complex square root of the real number x, where x may be negative.
    pub fn sqrt_real(x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sqrt_real(x).wrap() }
    }

    /// The function returns the complex number z raised to the complex power a, z^a.
    /// This is computed as \exp(\log(z)*a) using complex logarithms and complex exponentials.
    pub fn pow(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_pow(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the complex number z raised to the real power x, z^x.
    pub fn pow_real(&self, x: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_pow_real(self.unwrap(), x).wrap() }
    }

    /// This function returns the complex exponential of the complex number z, \exp(z).
    pub fn exp(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_exp(self.unwrap()).wrap() }
    }

    /// This function returns the complex natural logarithm (base e) of the complex number z,
    /// \log(z).
    ///
    /// The branch cut is the negative real axis.
    pub fn log(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_log(self.unwrap()).wrap() }
    }

    /// This function returns the complex base-10 logarithm of the complex number z, \log_10 (z).
    pub fn log10(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_log10(self.unwrap()).wrap() }
    }

    /// This function returns the complex base-b logarithm of the complex number z, \log_b(z).
    /// This quantity is computed as the ratio \log(z)/\log(b).
    pub fn log_b(&self, other: &ComplexF64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_log_b(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the complex sine of the complex number z, \sin(z) = (\exp(iz) -
    /// \exp(-iz))/(2i).
    pub fn sin(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sin(self.unwrap()).wrap() }
    }

    /// This function returns the complex cosine of the complex number z, \cos(z) = (\exp(iz) +
    /// \exp(-iz))/2.
    pub fn cos(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_cos(self.unwrap()).wrap() }
    }

    /// This function returns the complex tangent of the complex number z, \tan(z) =
    /// \sin(z)/\cos(z).
    pub fn tan(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_tan(self.unwrap()).wrap() }
    }

    /// This function returns the complex secant of the complex number z, \sec(z) = 1/\cos(z).
    pub fn sec(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sec(self.unwrap()).wrap() }
    }

    /// This function returns the complex cosecant of the complex number z, \csc(z) = 1/\sin(z).
    pub fn csc(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_csc(self.unwrap()).wrap() }
    }

    /// This function returns the complex cotangent of the complex number z, \cot(z) = 1/\tan(z).
    pub fn cot(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_cot(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsine of the complex number z, \arcsin(z).
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arcsin(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsin(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsine of the real number z, \arcsin(z).
    /// 
    /// * For z between -1 and 1, the function returns a real value in the range [-\pi/2,\pi/2].
    /// * For z less than -1 the result has a real part of -\pi/2 and a positive imaginary part.
    /// * For z greater than 1 the result has a real part of \pi/2 and a negative imaginary part.
    pub fn arcsin_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsin_real(z).wrap() }
    }

    /// This function returns the complex arccosine of the complex number z, \arccos(z).
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arccos(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccos(self.unwrap()).wrap() }
    }

    /// This function returns the complex arccosine of the real number z, \arccos(z).
    /// 
    /// * For z between -1 and 1, the function returns a real value in the range [0,\pi].
    /// * For z less than -1 the result has a real part of \pi and a negative imaginary part.
    /// * For z greater than 1 the result is purely imaginary and positive.
    pub fn arccos_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccos_real(z).wrap() }
    }

    /// This function returns the complex arctangent of the complex number z, \arctan(z).
    /// The branch cuts are on the imaginary axis, below -i and above i.
    pub fn arctan(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arctan(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsecant of the complex number z, \arcsec(z) =
    /// \arccos(1/z).
    pub fn arcsec(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsec(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsecant of the real number z, \arcsec(z) = \arccos(1/z).
    pub fn arcsec_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsec_real(z).wrap() }
    }

    /// This function returns the complex arccosecant of the complex number z, \arccsc(z) =
    /// \arcsin(1/z).
    pub fn arccsc(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccsc(self.unwrap()).wrap() }
    }

    /// This function returns the complex arccosecant of the real number z, \arccsc(z) =
    /// \arcsin(1/z).
    pub fn arccsc_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccsc_real(z).wrap() }
    }

    /// This function returns the complex arccotangent of the complex number z, \arccot(z) =
    /// \arctan(1/z).
    pub fn arccot(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccot(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic sine of the complex number z, \sinh(z) =
    /// (\exp(z) - \exp(-z))/2.
    pub fn sinh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sinh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cosine of the complex number z, \cosh(z) =
    /// (\exp(z) + \exp(-z))/2.
    pub fn cosh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_cosh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic tangent of the complex number z, \tanh(z) =
    /// \sinh(z)/\cosh(z).
    pub fn tanh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_tanh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic secant of the complex number z, \sech(z) =
    /// 1/\cosh(z).
    pub fn sech(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_sech(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cosecant of the complex number z, \csch(z) =
    /// 1/\sinh(z).
    pub fn csch(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_csch(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cotangent of the complex number z, \coth(z) =
    /// 1/\tanh(z).
    pub fn coth(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_coth(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arcsine of the complex number z, \arcsinh(z).
    /// The branch cuts are on the imaginary axis, below -i and above i.
    pub fn arcsinh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsinh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosine of the complex number z, \arccosh(z).
    /// The branch cut is on the real axis, less than 1.
    /// Note that in this case we use the negative square root in formula 4.6.21 of Abramowitz &
    /// Stegun giving \arccosh(z)=\log(z-\sqrt{z^2-1}).
    pub fn arccosh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccosh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosine of the real number z, \arccosh(z).
    pub fn arccosh_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccosh_real(z).wrap() }
    }

    /// This function returns the complex hyperbolic arctangent of the complex number z,
    /// \arctanh(z).
    ///
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arctanh(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arctanh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arctangent of the real number z, \arctanh(z).
    pub fn arctanh_real(z: f64) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arctanh_real(z).wrap() }
    }

    /// This function returns the complex hyperbolic arcsecant of the complex number z, \arcsech(z)
    /// = \arccosh(1/z).
    pub fn arcsech(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arcsech(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosecant of the complex number z,
    /// \arccsch(z) = \arcsin(1/z).
    pub fn arccsch(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccsch(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccotangent of the complex number z,
    /// \arccoth(z) = \arctanh(1/z).
    pub fn arccoth(&self) -> ComplexF64 {
        unsafe { ::ffi::gsl_complex_arccoth(self.unwrap()).wrap() }
    }
}

impl Debug for ComplexF64 {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "[{}, {}]", self.dat[0], self.dat[1])
    }
}

impl Clone for ComplexF64 {
    fn clone(&self) -> ComplexF64 {
        ComplexF64 {
            dat: [self.dat[0], self.dat[1]]
        }
    }
}

impl Default for ComplexF64 {
    fn default() -> ComplexF64 {
        ComplexF64 {
            dat: [0f64, 0f64]
        }
    }
}

impl CFFI<ffi::gsl_complex> for ComplexF64 {
    fn wrap(t: ffi::gsl_complex) -> ComplexF64 {
        unsafe { ::std::mem::transmute(t) }
    }

    fn unwrap(self) -> ffi::gsl_complex {
        unsafe { ::std::mem::transmute(self) }
    }
}

impl CFFI<ffi::gsl_complex_float> for ComplexF64 {
    fn wrap(t: ffi::gsl_complex_float) -> ComplexF64 {
        ComplexF64 {
            dat: [t.dat[0] as f64, t.dat[1] as f64],
        }
    }

    fn unwrap(self) -> ffi::gsl_complex_float {
        ffi::gsl_complex_float {
            dat: [self.dat[0] as f32, self.dat[1] as f32],
        }
    }
}

impl FFFI<ComplexF32> for ffi::gsl_complex {
    fn wrap(self) -> ComplexF32 {
        ComplexF32 {
            dat: [self.dat[0] as f32, self.dat[1] as f32],
        }
    }

    fn unwrap(t: ComplexF32) -> ffi::gsl_complex {
        ffi::gsl_complex {
            dat: [t.dat[0] as f64, t.dat[1] as f64],
        }
    }
}

impl FFFI<ComplexF64> for ffi::gsl_complex {
    fn wrap(self) -> ComplexF64 {
        unsafe { ::std::mem::transmute(self) }
    }

    fn unwrap(t: ComplexF64) -> ffi::gsl_complex {
        unsafe { ::std::mem::transmute(t) }
    }
}

#[repr(C)]
#[derive(Copy, PartialEq)]
pub struct ComplexF32 {
    pub dat: [f32; 2]
}

impl ComplexF32 {
    /// This function uses the rectangular Cartesian components (x,y) to return the complex number
    /// z = x + i y.
    pub fn rect(x: f32, y: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_rect(x as f64, y as f64).wrap() }
    }

    /// This function returns the complex number z = r \exp(i \theta) = r (\cos(\theta) + i
    /// \sin(\theta)) from the polar representation (r,theta).
    pub fn polar(r: f32, theta: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_polar(r as f64, theta as f64).wrap() }
    }

    /// This function returns the argument of the complex number z, \arg(z), where -\pi < \arg(z)
    /// <= \pi.
    pub fn arg(&self) -> f32 {
        unsafe { ::ffi::gsl_complex_arg(self.unwrap()) as f32 }
    }

    /// This function returns the magnitude of the complex number z, |z|.
    pub fn abs(&self) -> f32 {
        unsafe { ::ffi::gsl_complex_abs(self.unwrap()) as f32 }
    }

    /// This function returns the squared magnitude of the complex number z, |z|^2.
    pub fn abs2(&self) -> f32 {
        unsafe { ::ffi::gsl_complex_abs2(self.unwrap()) as f32 }
    }

    /// This function returns the natural logarithm of the magnitude of the complex number z,
    /// \log|z|.
    ///
    /// It allows an accurate evaluation of \log|z| when |z| is close to one.
    /// The direct evaluation of log(gsl_complex_abs(z)) would lead to a loss of precision in
    /// this case.
    pub fn logabs(&self) -> f32 {
        unsafe { ::ffi::gsl_complex_logabs(self.unwrap()) as f32 }
    }

    /// This function returns the sum of the complex numbers a and b, z=a+b.
    pub fn add(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_add(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the difference of the complex numbers a and b, z=a-b.
    pub fn sub(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sub(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the product of the complex numbers a and b, z=ab.
    pub fn mul(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_mul(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the quotient of the complex numbers a and b, z=a/b.
    pub fn div(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_div(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the sum of the complex number a and the real number x, z=a+x.
    pub fn add_real(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_add_real(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the difference of the complex number a and the real number x, z=a-x.
    pub fn sub_real(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sub_real(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the product of the complex number a and the real number x, z=ax.
    pub fn mul_real(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_mul_real(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the quotient of the complex number a and the real number x, z=a/x.
    pub fn div_real(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_div_real(self.unwrap(), x as f64).wrap() }
    }
    
    /// This function returns the sum of the complex number a and the imaginary number iy, z=a+iy.
    pub fn add_imag(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_add_imag(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the difference of the complex number a and the imaginary number iy, z=a-iy.
    pub fn sub_imag(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sub_imag(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the product of the complex number a and the imaginary number iy, z=a*(iy).
    pub fn mul_imag(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_mul_imag(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the quotient of the complex number a and the imaginary number iy, z=a/(iy).
    pub fn div_imag(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_div_imag(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the complex conjugate of the complex number z, z^* = x - i y.
    pub fn conjugate(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_conjugate(self.unwrap()).wrap() }
    }

    /// This function returns the inverse, or reciprocal, of the complex number z, 1/z = (x - i y)/
    /// (x^2 + y^2).
    pub fn inverse(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_inverse(self.unwrap()).wrap() }
    }

    /// This function returns the negative of the complex number z, -z = (-x) + i(-y).
    pub fn negative(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_negative(self.unwrap()).wrap() }
    }

    /// This function returns the square root of the complex number z, \sqrt z.
    ///
    /// The branch cut is the negative real axis. The result always lies in the right half of the
    /// complex plane.
    pub fn sqrt(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sqrt(self.unwrap()).wrap() }
    }

    /// This function returns the complex square root of the real number x, where x may be negative.
    pub fn sqrt_real(x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sqrt_real(x as f64).wrap() }
    }

    /// The function returns the complex number z raised to the complex power a, z^a.
    ///
    /// This is computed as \exp(\log(z)*a) using complex logarithms and complex exponentials.
    pub fn pow(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_pow(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the complex number z raised to the real power x, z^x.
    pub fn pow_real(&self, x: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_pow_real(self.unwrap(), x as f64).wrap() }
    }

    /// This function returns the complex exponential of the complex number z, \exp(z).
    pub fn exp(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_exp(self.unwrap()).wrap() }
    }

    /// This function returns the complex natural logarithm (base e) of the complex number z, \log(z).
    /// The branch cut is the negative real axis.
    pub fn log(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_log(self.unwrap()).wrap() }
    }

    /// This function returns the complex base-10 logarithm of the complex number z, \log_10 (z).
    pub fn log10(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_log10(self.unwrap()).wrap() }
    }

    /// This function returns the complex base-b logarithm of the complex number z, \log_b(z).
    /// This quantity is computed as the ratio \log(z)/\log(b).
    pub fn log_b(&self, other: &ComplexF32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_log_b(self.unwrap(), other.unwrap()).wrap() }
    }

    /// This function returns the complex sine of the complex number z, \sin(z) = (\exp(iz) -
    /// \exp(-iz))/(2i).
    pub fn sin(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sin(self.unwrap()).wrap() }
    }

    /// This function returns the complex cosine of the complex number z, \cos(z) = (\exp(iz) +
    /// \exp(-iz))/2.
    pub fn cos(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_cos(self.unwrap()).wrap() }
    }

    /// This function returns the complex tangent of the complex number z, \tan(z) =
    /// \sin(z)/\cos(z).
    pub fn tan(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_tan(self.unwrap()).wrap() }
    }

    /// This function returns the complex secant of the complex number z, \sec(z) = 1/\cos(z).
    pub fn sec(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sec(self.unwrap()).wrap() }
    }

    /// This function returns the complex cosecant of the complex number z, \csc(z) = 1/\sin(z).
    pub fn csc(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_csc(self.unwrap()).wrap() }
    }

    /// This function returns the complex cotangent of the complex number z, \cot(z) = 1/\tan(z).
    pub fn cot(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_cot(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsine of the complex number z, \arcsin(z).
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arcsin(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsin(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsine of the real number z, \arcsin(z).
    /// 
    /// * For z between -1 and 1, the function returns a real value in the range [-\pi/2,\pi/2].
    /// * For z less than -1 the result has a real part of -\pi/2 and a positive imaginary part.
    /// * For z greater than 1 the result has a real part of \pi/2 and a negative imaginary part.
    pub fn arcsin_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsin_real(z as f64).wrap() }
    }

    /// This function returns the complex arccosine of the complex number z, \arccos(z).
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arccos(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccos(self.unwrap()).wrap() }
    }

    /// This function returns the complex arccosine of the real number z, \arccos(z).
    /// 
    /// * For z between -1 and 1, the function returns a real value in the range [0,\pi].
    /// * For z less than -1 the result has a real part of \pi and a negative imaginary part.
    /// * For z greater than 1 the result is purely imaginary and positive.
    pub fn arccos_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccos_real(z as f64).wrap() }
    }

    /// This function returns the complex arctangent of the complex number z, \arctan(z).
    /// The branch cuts are on the imaginary axis, below -i and above i.
    pub fn arctan(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arctan(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsecant of the complex number z, \arcsec(z) = 
    /// \arccos(1/z).
    pub fn arcsec(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsec(self.unwrap()).wrap() }
    }

    /// This function returns the complex arcsecant of the real number z, \arcsec(z) = \arccos(1/z).
    pub fn arcsec_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsec_real(z as f64).wrap() }
    }

    /// This function returns the complex arccosecant of the complex number z, \arccsc(z) =
    /// \arcsin(1/z).
    pub fn arccsc(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccsc(self.unwrap()).wrap() }
    }

    /// This function returns the complex arccosecant of the real number z, \arccsc(z) =
    /// \arcsin(1/z).
    pub fn arccsc_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccsc_real(z as f64).wrap() }
    }

    /// This function returns the complex arccotangent of the complex number z, \arccot(z) =
    /// \arctan(1/z).
    pub fn arccot(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccot(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic sine of the complex number z, \sinh(z) =
    /// (\exp(z) - \exp(-z))/2.
    pub fn sinh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sinh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cosine of the complex number z, \cosh(z) =
    /// (\exp(z) + \exp(-z))/2.
    pub fn cosh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_cosh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic tangent of the complex number z, \tanh(z) =
    /// \sinh(z)/\cosh(z).
    pub fn tanh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_tanh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic secant of the complex number z, \sech(z) =
    /// 1/\cosh(z).
    pub fn sech(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_sech(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cosecant of the complex number z, \csch(z) =
    /// 1/\sinh(z).
    pub fn csch(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_csch(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic cotangent of the complex number z, \coth(z) =
    /// 1/\tanh(z).
    pub fn coth(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_coth(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arcsine of the complex number z, \arcsinh(z).
    /// The branch cuts are on the imaginary axis, below -i and above i.
    pub fn arcsinh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsinh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosine of the complex number z, \arccosh(z).
    ///
    /// The branch cut is on the real axis, less than 1.
    ///
    /// Note that in this case we use the negative square root in formula 4.6.21 of Abramowitz &
    /// Stegun giving \arccosh(z)=\log(z-\sqrt{z^2-1}).
    pub fn arccosh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccosh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosine of the real number z, \arccosh(z).
    pub fn arccosh_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccosh_real(z as f64).wrap() }
    }

    /// This function returns the complex hyperbolic arctangent of the complex number z, 
    /// arctanh(z).
    ///
    /// The branch cuts are on the real axis, less than -1 and greater than 1.
    pub fn arctanh(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arctanh(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arctangent of the real number z, \arctanh(z).
    pub fn arctanh_real(z: f32) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arctanh_real(z as f64).wrap() }
    }

    /// This function returns the complex hyperbolic arcsecant of the complex number z, \arcsech(z)
    /// = \arccosh(1/z).
    pub fn arcsech(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arcsech(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccosecant of the complex number z,
    /// \arccsch(z) = \arcsin(1/z).
    pub fn arccsch(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccsch(self.unwrap()).wrap() }
    }

    /// This function returns the complex hyperbolic arccotangent of the complex number z,
    /// \arccoth(z) = \arctanh(1/z).
    pub fn arccoth(&self) -> ComplexF32 {
        unsafe { ::ffi::gsl_complex_arccoth(self.unwrap()).wrap() }
    }
}

impl Debug for ComplexF32 {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "[{}, {}]", self.dat[0], self.dat[1])
    }
}

impl Clone for ComplexF32 {
    fn clone(&self) -> ComplexF32 {
        ComplexF32 {
            dat: [self.dat[0], self.dat[1]]
        }
    }
}

impl Default for ComplexF32 {
    fn default() -> ComplexF32 {
        ComplexF32 {
            dat: [0f32, 0f32]
        }
    }
}

impl CFFI<ffi::gsl_complex> for ComplexF32 {
    fn wrap(s: ffi::gsl_complex) -> ComplexF32 {
        ComplexF32 {
            dat: [s.dat[0] as f32, s.dat[1] as f32],
        }
    }

    fn unwrap(self) -> ffi::gsl_complex {
        ffi::gsl_complex {
            dat: [self.dat[0] as f64, self.dat[1] as f64],
        }
    }
}

impl CFFI<ffi::gsl_complex_float> for ComplexF32 {
    fn wrap(s: ffi::gsl_complex_float) -> ComplexF32 {
        unsafe { ::std::mem::transmute(s) }
    }

    fn unwrap(self) -> ffi::gsl_complex_float {
        unsafe { ::std::mem::transmute(self) }
    }
}

// All these tests have been tested against the following C code:
//
// ```ignore
// #include <gsl/gsl_complex.h>
// #include <gsl/gsl_complex_math.h>
// #include <gsl/gsl_inline.h>
// #include <gsl/gsl_complex.h>
//
// void print_complex(gsl_complex *c, const char *text) {
//   printf("%s: %f %f\n", text, c->dat[0], c->dat[1]);
// }
//
// int main (void)
// {
//   gsl_complex c = gsl_complex_rect(10., 10.);
//   gsl_complex c2 = gsl_complex_rect(1., -1.);
//   print_complex(&c, "rect");
//   print_complex(&c2, "rect");
//   gsl_complex c3 = gsl_complex_polar(5., 7.);
//   print_complex(&c3, "polar");
//
//   printf("-> %f\n", gsl_complex_arg(c3));
//   printf("-> %f\n", gsl_complex_abs(c3));
//   printf("-> %f\n", gsl_complex_abs2(c3));
//   printf("-> %f\n", gsl_complex_logabs(c3));
//
//   {
//     gsl_complex c4 = gsl_complex_add(c3, c2);
//     print_complex(&c4, "\nadd");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sub(c3, c2);
//     print_complex(&c4, "sub");
//   }
//   {
//     gsl_complex c4 = gsl_complex_mul(c3, c2);
//     print_complex(&c4, "mul");
//   }
//   {
//     gsl_complex c4 = gsl_complex_div(c3, c2);
//     print_complex(&c4, "div");
//   }
//   {
//     gsl_complex c4 = gsl_complex_add_real(c3, 5.);
//     print_complex(&c4, "add_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sub_real(c3, 5.);
//     print_complex(&c4, "sub_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_mul_real(c3, 5.);
//     print_complex(&c4, "mul_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_div_real(c3, 5.);
//     print_complex(&c4, "div_real");
//   }
//
//
//   {
//     gsl_complex c4 = gsl_complex_add_imag(c3, 5.);
//     print_complex(&c4, "\nadd_imag");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sub_imag(c3, 5.);
//     print_complex(&c4, "sub_imag");
//   }
//   {
//     gsl_complex c4 = gsl_complex_mul_imag(c3, 5.);
//     print_complex(&c4, "mul_imag");
//   }
//   {
//     gsl_complex c4 = gsl_complex_div_imag(c3, 5.);
//     print_complex(&c4, "div_imag");
//   }
//
//
//   {
//     gsl_complex c4 = gsl_complex_conjugate(c3);
//     print_complex(&c4, "\nconjugate");
//   }
//   {
//     gsl_complex c4 = gsl_complex_inverse(c3);
//     print_complex(&c4, "inverse");
//   }
//   {
//     gsl_complex c4 = gsl_complex_negative(c3);
//     print_complex(&c4, "negative");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sqrt(c3);
//     print_complex(&c4, "sqrt");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sqrt_real(5.);
//     print_complex(&c4, "sqrt_real");
//   }
//
//
//   {
//     gsl_complex c4 = gsl_complex_pow(c3, c2);
//     print_complex(&c4, "\npow");
//   }
//   {
//     gsl_complex c4 = gsl_complex_pow_real(c3, 5.);
//     print_complex(&c4, "pow_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_exp(c3);
//     print_complex(&c4, "exp");
//   }
//   {
//     gsl_complex c4 = gsl_complex_log(c3);
//     print_complex(&c4, "log");
//   }
//   {
//     gsl_complex c4 = gsl_complex_log10(c3);
//     print_complex(&c4, "log10");
//   }
//   {
//     gsl_complex c4 = gsl_complex_log_b(c3, c2);
//     print_complex(&c4, "log_b");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sin(c3);
//     print_complex(&c4, "sin");
//   }
//   {
//     gsl_complex c4 = gsl_complex_cos(c3);
//     print_complex(&c4, "cos");
//   }
//   {
//     gsl_complex c4 = gsl_complex_tan(c3);
//     print_complex(&c4, "tan");
//   }
//
//
//   {
//     gsl_complex c4 = gsl_complex_sec(c3);
//     print_complex(&c4, "\nsec");
//   }
//   {
//     gsl_complex c4 = gsl_complex_csc(c3);
//     print_complex(&c4, "csc");
//   }
//   {
//     gsl_complex c4 = gsl_complex_cot(c3);
//     print_complex(&c4, "cot");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsin(c3);
//     print_complex(&c4, "arcsin");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsin_real(5.);
//     print_complex(&c4, "arcsin_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccos(c3);
//     print_complex(&c4, "arccos");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccos_real(5.);
//     print_complex(&c4, "arccos_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arctan(c3);
//     print_complex(&c4, "arctan");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsec(c3);
//     print_complex(&c4, "arcsec");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsec_real(5.);
//     print_complex(&c4, "arcsec_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccsc(c3);
//     print_complex(&c4, "arccsc");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccsc_real(5.);
//     print_complex(&c4, "arccsc_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccot(c3);
//     print_complex(&c4, "arccot");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sinh(c3);
//     print_complex(&c4, "sinh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_cosh(c3);
//     print_complex(&c4, "cosh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_tanh(c3);
//     print_complex(&c4, "tanh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_sech(c3);
//     print_complex(&c4, "sech");
//   }
//   {
//     gsl_complex c4 = gsl_complex_csch(c3);
//     print_complex(&c4, "csch");
//   }
//   {
//     gsl_complex c4 = gsl_complex_coth(c3);
//     print_complex(&c4, "coth");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsinh(c3);
//     print_complex(&c4, "arcsinh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccosh(c3);
//     print_complex(&c4, "arccosh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccosh_real(5.);
//     print_complex(&c4, "arccosh_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arctanh(c3);
//     print_complex(&c4, "arctanh");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arctanh_real(5.);
//     print_complex(&c4, "arctanh_real");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arcsech(c3);
//     print_complex(&c4, "arcsech");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccsch(c3);
//     print_complex(&c4, "arccsch");
//   }
//   {
//     gsl_complex c4 = gsl_complex_arccoth(c3);
//     print_complex(&c4, "arccoth");
//   }
//   return 0;
// }
// ```
#[test]
fn complex_f64() {
    let v = ComplexF64::rect(10., 10.);
    assert_eq!(v, ComplexF64 { dat: [10., 10.] });
    let v2 = ComplexF64::rect(1., -1.);
    assert_eq!(v2, ComplexF64 { dat: [1., -1.] });
    let v = ComplexF64::polar(5., 7.);
    assert_eq!(format!("{:.4} {:.4}", v.dat[0], v.dat[1]), "3.7695 3.2849".to_owned());

    let arg = v.arg();
    assert_eq!(format!("{:.4}", arg), "0.7168".to_owned());
    let arg = v.abs();
    assert_eq!(format!("{:.3}", arg), "5.000".to_owned());
    let arg = v.abs2();
    assert_eq!(format!("{:.3}", arg), "25.000".to_owned());
    let arg = v.logabs();
    assert_eq!(format!("{:.4}", arg), "1.6094".to_owned());

    let v3 = v.add(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "4.7695 2.2849".to_owned());
    let v3 = v.sub(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.7695 4.2849".to_owned());
    let v3 = v.mul(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "7.0544 -0.4846".to_owned());
    let v3 = v.div(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2423 3.5272".to_owned());
    let v3 = v.add_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "8.7695 3.2849".to_owned());
    let v3 = v.sub_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-1.2305 3.2849".to_owned());
    let v3 = v.mul_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "18.8476 16.4247".to_owned());
    let v3 = v.div_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7539 0.6570".to_owned());

    let v3 = v.add_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 8.2849".to_owned());
    let v3 = v.sub_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -1.7151".to_owned());
    let v3 = v.mul_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-16.4247 18.8476".to_owned());
    let v3 = v.div_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6570 -0.7539".to_owned());

    let v3 = v.conjugate();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -3.2849".to_owned());
    let v3 = v.inverse();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1508 -0.1314".to_owned());
    let v3 = v.negative();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-3.7695 -3.2849".to_owned());
    let v3 = v.sqrt();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.0940 0.7844".to_owned());
    let v3 = ComplexF64::sqrt_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2361 0.0000".to_owned());

    let v3 = v.pow(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "6.4240 -7.9737".to_owned());
    let v3 = v.pow_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-2824.0381 -1338.0708".to_owned());
    let v3 = v.exp();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-42.9142 -6.1938".to_owned());
    let v3 = v.log();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.6094 0.7168".to_owned());
    let v3 = v.log10();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6990 0.3113".to_owned());
    let v3 = v.log_b(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0071 2.0523".to_owned());
    let v3 = v.sin();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-7.8557 -10.7913".to_owned());
    let v3 = v.cos();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-10.8216 7.8337".to_owned());
    let v3 = v.tan();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 0.9991".to_owned());

    let v3 = v.sec();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0606 -0.0439".to_owned());
    let v3 = v.csc();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0441 0.0606".to_owned());
    let v3 = v.cot();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 -1.0009".to_owned());
    let v3 = v.arcsin();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.8440 2.3014".to_owned());
    let v3 = ComplexF64::arcsin_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.5708 -2.2924".to_owned());
    let v3 = v.arccos();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7268 -2.3014".to_owned());
    let v3 = ComplexF64::arccos_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0000 2.2924".to_owned());
    let v3 = v.arctan();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4186 0.1291".to_owned());
    let v3 = v.arcsec();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4208 0.1325".to_owned());
    let v3 = ComplexF64::arcsec_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.3694 0.0000".to_owned());
    let v3 = v.arccsc();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1500 -0.1325".to_owned());
    let v3 = ComplexF64::arccsc_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2014 0.0000".to_owned());
    let v3 = v.arccot();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1522 -0.1291".to_owned());
    let v3 = v.sinh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4457 -3.0986".to_owned());
    let v3 = v.cosh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4685 -3.0953".to_owned());
    let v3 = v.tanh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.9990 0.0003".to_owned());
    let v3 = v.sech();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0456 0.0066".to_owned());
    let v3 = v.csch();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0457 0.0066".to_owned());
    let v3 = v.coth();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.0010 -0.0003".to_owned());
    let v3 = v.arcsinh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3041 0.7070".to_owned());
    let v3 = v.arccosh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3014 0.7268".to_owned());
    let v3 = ComplexF64::arccosh_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2924 0.0000".to_owned());
    let v3 = v.arctanh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 1.4372".to_owned());
    let v3 = ComplexF64::arctanh_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2027 -1.5708".to_owned());
    let v3 = v.arcsech();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1325 -1.4208".to_owned());
    let v3 = v.arccsch();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1515 -0.1303".to_owned());
    let v3 = v.arccoth();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 -0.1336".to_owned());
}

#[test]
fn complex_f32() {
    let v = ComplexF32::rect(10., 10.);
    assert_eq!(v, ComplexF32 { dat: [10., 10.] });
    let v2 = ComplexF32::rect(1., -1.);
    assert_eq!(v2, ComplexF32 { dat: [1., -1.] });
    let v = ComplexF32::polar(5., 7.);
    assert_eq!(format!("{:.4} {:.4}", v.dat[0], v.dat[1]), "3.7695 3.2849".to_owned());

    let arg = v.arg();
    assert_eq!(format!("{:.4}", arg), "0.7168".to_owned());
    let arg = v.abs();
    assert_eq!(format!("{:.3}", arg), "5.000".to_owned());
    let arg = v.abs2();
    assert_eq!(format!("{:.3}", arg), "25.000".to_owned());
    let arg = v.logabs();
    assert_eq!(format!("{:.4}", arg), "1.6094".to_owned());

    let v3 = v.add(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "4.7695 2.2849".to_owned());
    let v3 = v.sub(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.7695 4.2849".to_owned());
    let v3 = v.mul(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "7.0544 -0.4846".to_owned());
    let v3 = v.div(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2423 3.5272".to_owned());
    let v3 = v.add_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "8.7695 3.2849".to_owned());
    let v3 = v.sub_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-1.2305 3.2849".to_owned());
    let v3 = v.mul_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "18.8476 16.4247".to_owned());
    let v3 = v.div_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7539 0.6570".to_owned());

    let v3 = v.add_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 8.2849".to_owned());
    let v3 = v.sub_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -1.7151".to_owned());
    let v3 = v.mul_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-16.4247 18.8476".to_owned());
    let v3 = v.div_imag(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6570 -0.7539".to_owned());

    let v3 = v.conjugate();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "3.7695 -3.2849".to_owned());
    let v3 = v.inverse();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1508 -0.1314".to_owned());
    let v3 = v.negative();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-3.7695 -3.2849".to_owned());
    let v3 = v.sqrt();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.0940 0.7844".to_owned());
    let v3 = ComplexF32::sqrt_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2361 0.0000".to_owned());

    let v3 = v.pow(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "6.4240 -7.9737".to_owned());
    let v3 = v.pow_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-2824.0381 -1338.0712".to_owned());
    let v3 = v.exp();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-42.9142 -6.1938".to_owned());
    let v3 = v.log();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.6094 0.7168".to_owned());
    let v3 = v.log10();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.6990 0.3113".to_owned());
    let v3 = v.log_b(&v2);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0071 2.0523".to_owned());
    let v3 = v.sin();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-7.8557 -10.7913".to_owned());
    let v3 = v.cos();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-10.8216 7.8337".to_owned());
    let v3 = v.tan();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 0.9991".to_owned());

    let v3 = v.sec();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0606 -0.0439".to_owned());
    let v3 = v.csc();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0441 0.0606".to_owned());
    let v3 = v.cot();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0027 -1.0009".to_owned());
    let v3 = v.arcsin();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.8440 2.3014".to_owned());
    let v3 = ComplexF32::arcsin_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.5708 -2.2924".to_owned());
    let v3 = v.arccos();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.7268 -2.3014".to_owned());
    let v3 = ComplexF32::arccos_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.0000 2.2924".to_owned());
    let v3 = v.arctan();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4186 0.1291".to_owned());
    let v3 = v.arcsec();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.4208 0.1325".to_owned());
    let v3 = ComplexF32::arcsec_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.3694 0.0000".to_owned());
    let v3 = v.arccsc();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1500 -0.1325".to_owned());
    let v3 = ComplexF32::arccsc_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2014 0.0000".to_owned());
    let v3 = v.arccot();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1522 -0.1291".to_owned());
    let v3 = v.sinh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4457 -3.0986".to_owned());
    let v3 = v.cosh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-21.4685 -3.0953".to_owned());
    let v3 = v.tanh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.9990 0.0003".to_owned());
    let v3 = v.sech();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0456 0.0066".to_owned());
    let v3 = v.csch();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "-0.0457 0.0066".to_owned());
    let v3 = v.coth();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "1.0010 -0.0003".to_owned());
    let v3 = v.arcsinh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3041 0.7070".to_owned());
    let v3 = v.arccosh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.3014 0.7268".to_owned());
    let v3 = ComplexF32::arccosh_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "2.2924 0.0000".to_owned());
    let v3 = v.arctanh();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 1.4372".to_owned());
    let v3 = ComplexF32::arctanh_real(5.);
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.2027 -1.5708".to_owned());
    let v3 = v.arcsech();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1325 -1.4208".to_owned());
    let v3 = v.arccsch();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1515 -0.1303".to_owned());
    let v3 = v.arccoth();
    assert_eq!(format!("{:.4} {:.4}", v3.dat[0], v3.dat[1]), "0.1493 -0.1336".to_owned());
}