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 +65
-1
lines changed Expand file tree Collapse file tree 2 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -873,7 +873,38 @@ public function arctan($scale = null)
873
873
return self ::simplePowerSerie (
874
874
$ this ,
875
875
DecimalConstants::zero (),
876
- $ scale
876
+ $ scale + 2
877
+ )->round ($ scale );
878
+ }
879
+
880
+ /**
881
+ * Calculates the arccotangente of this with the highest possible accuracy
882
+ *
883
+ * @param integer $scale
884
+ * @return Decimal
885
+ */
886
+ public function arccot ($ scale = null ) {
887
+ $ scale = ($ scale === null ) ? 32 : $ scale ;
888
+
889
+ $ piOverTwo = DecimalConstants::pi ()->div (Decimal::fromInteger (2 ), $ scale + 2 );
890
+ if ($ this ->round ($ scale )->isZero ()) {
891
+ return $ piOverTwo ->round ($ scale );
892
+ }
893
+
894
+ $ piOverFour = DecimalConstants::pi ()->div (Decimal::fromInteger (4 ), $ scale + 2 );
895
+ if ($ this ->round ($ scale )->equals (DecimalConstants::one ())) {
896
+ return $ piOverFour ->round ($ scale );
897
+ }
898
+ if ($ this ->round ($ scale )->equals (DecimalConstants::negativeOne ())) {
899
+ return DecimalConstants::negativeOne ()->mul ($ piOverFour , $ scale + 2 )->round ($ scale );
900
+ }
901
+
902
+ return $ piOverTwo ->sub (
903
+ self ::simplePowerSerie (
904
+ $ this ,
905
+ DecimalConstants::zero (),
906
+ $ scale + 2
907
+ )
877
908
)->round ($ scale );
878
909
}
879
910
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Litipk \BigNumbers \Decimal as Decimal ;
4
+
5
+ /**
6
+ * @group arccot
7
+ */
8
+ class DecimalArccotTest extends PHPUnit_Framework_TestCase
9
+ {
10
+ public function arccotProvider () {
11
+ // Some values provided by wolframalpha
12
+ return [
13
+ ['0.154 ' , '1.41799671285823 ' , 14 ],
14
+ ['0 ' , '1.57079632679489662 ' , 17 ],
15
+ ['-1 ' , '-0.78540 ' , 5 ],
16
+ ];
17
+ }
18
+
19
+ /**
20
+ * @dataProvider arccotProvider
21
+ */
22
+ public function testSimple ($ nr , $ answer , $ digits )
23
+ {
24
+ $ x = Decimal::fromString ($ nr );
25
+ $ arccotX = $ x ->arccot ($ digits );
26
+
27
+ $ this ->assertTrue (
28
+ Decimal::fromString ($ answer )->equals ($ arccotX ),
29
+ "The answer must be " . $ answer . ", but was " . $ arccotX
30
+ );
31
+ }
32
+
33
+ }
You can’t perform that action at this time.
0 commit comments