This repository was archived by the owner on Dec 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -713,6 +713,25 @@ function ($i) {
713
713
);
714
714
}
715
715
716
+ /**
717
+ * Calculates the cosecant of this with the highest possible accuracy
718
+ * Note that accuracy is limited by the accuracy of predefined PI;
719
+ *
720
+ * @param integer $scale
721
+ * @return Decimal
722
+ */
723
+ public function cosec ($ scale = null )
724
+ {
725
+ $ sin = $ this ->sin ($ scale + 2 );
726
+ if ($ sin ->isZero ()) {
727
+ throw new \DomainException (
728
+ "The cosecant of this 'angle' is undefined. "
729
+ );
730
+ }
731
+
732
+ return Decimal::fromInteger (1 )->div ($ sin )->round ($ scale );
733
+ }
734
+
716
735
/**
717
736
* Calculates the cosine of this method with the highest possible accuracy
718
737
* Note that accuracy is limited by the accuracy of predefined PI;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Litipk \BigNumbers \Decimal as Decimal ;
4
+
5
+ /**
6
+ * @group cosec
7
+ */
8
+ class DecimalCosecTest extends PHPUnit_Framework_TestCase
9
+ {
10
+ public function cosecProvider () {
11
+ // Some values provided by Mathematica
12
+ return [
13
+ ['1 ' , '1.18839510577812 ' , 14 ],
14
+ ['123.123 ' , '-1.76874094322450309 ' , 17 ],
15
+ ['15000000000 ' , '1.44570405082842149818 ' , 20 ]
16
+ ];
17
+ }
18
+
19
+ /**
20
+ * @dataProvider cosecProvider
21
+ */
22
+ public function testSimple ($ nr , $ answer , $ digits )
23
+ {
24
+ $ x = Decimal::fromString ($ nr );
25
+ $ cosecX = $ x ->cosec ((int )$ digits );
26
+
27
+ $ this ->assertTrue (
28
+ Decimal::fromString ($ answer )->equals ($ cosecX ),
29
+ "The answer must be " . $ answer . ", but was " . $ cosecX
30
+ );
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments