* Bug 16097 fixed: tanh() & coth() improved
[scilab.git] / scilab / modules / elementary_functions / tests / unit_tests / tanh.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2019 - Samuel GOUGEON
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8 // <-- CLI SHELL MODE -->
9 // <-- NO CHECK REF -->
10
11 // Unitary tests for tanh()
12
13 s = sprand(5, 4, 0.3);
14 assert_checkequal(tanh(s), sparse(tanh(full(s))));
15
16 x = [0:0.01:0.1 0.1:0.1:1 1:20]';
17 r = [
18    0.
19    0.0099996666799994604
20    0.0199973337599309332
21    0.0299910032388201429
22    0.0399786803111635697
23    0.0499583749578799766
24    0.059928103529143503
25    0.0698858903164289724
26    0.079829769111131349 
27    0.0897577847471601048
28    0.0996679946249558191
29    0.09966799462495583
30    0.19737532022490401
31    0.29131261245159096
32    0.37994896225522484
33    0.46211715726000979
34    0.5370495669980353
35    0.60436777711716361
36    0.66403677026784891
37    0.71629787019902447
38    0.76159415595576485
39    0.76159415595576485
40    0.964027580075817
41    0.99505475368673058
42    0.99932929973906703
43    0.999909204262595
44    0.9999877116507956
45    0.99999833694394458
46    0.99999977492967596
47    0.999999969540041
48    0.99999999587769284
49    0.99999999944210638
50    0.99999999992449728
51    0.99999999998978184
52    0.99999999999861722
53    0.99999999999981282
54    0.99999999999997446
55    0.99999999999999656
56    0.99999999999999956
57    0.99999999999999978
58    1.
59    ];
60 assert_checkalmostequal(tanh(x), r, %eps);
61 assert_checkalmostequal(tanh(-x), -r, %eps);
62 assert_checkequal(1/tanh(-0), -%inf);