-
-
Notifications
You must be signed in to change notification settings - Fork 6
04. Trigonometry
Trigonometry methods are only available on objects which implement DecimalInterface. If you want to do trigonometry functions on an object that implement FractionInterface, calling the asDecimal() method will return the numerator divided by the denominator as an instance of ImmutableNumber which implements the DecimalInterface.
This method applies the sin function to the current Value. If $precision is null, the precision setting of the object is used. If a precision of greater than 99 is supplied as an argument, or if the object has a precision of greater than 99, the precision is silently reduced to 99.
If the $round argument is true the last digit will be rounded; if the $round argument is false the last digit will be truncated. It is important to note that the last digit (prior to rounding) is guaranteed to be accurate, so rounding will actually reduce the precision, in effect, by one. However, it will capture some of the behavior after the precision limit.
<?php
use Samsara\Fermat\Values\ImmutableNumber;
$four = new ImmutableNumber(4);
$largeInt = new ImmutableNumber('1000000000000000000000000000');
echo $four->sin(); // Prints: "-0.7568024953"
echo $largeInt->sin(15); // Prints: "0.718063496139118"This method applies the cos function to the current Value. If $precision is null, the precision setting of the object is used. If a precision of greater than 99 is supplied as an argument, or if the object has a precision of greater than 99, the precision is silently reduced to 99.
If the $round argument is true the last digit will be rounded; if the $round argument is false the last digit will be truncated. It is important to note that the last digit (prior to rounding) is guaranteed to be accurate, so rounding will actually reduce the precision, in effect, by one. However, it will capture some of the behavior after the precision limit.
<?php
use Samsara\Fermat\Values\ImmutableNumber;
$four = new ImmutableNumber(4);
$largeInt = new ImmutableNumber('1000000000000000000000000000');
echo $four->cos(); // Prints: "-0.6536436209"
echo $largeInt->cos(15); // Prints: "-0.695977596990354"This method applies the tan function to the current Value. If $precision is null, the precision setting of the object is used. If a precision of greater than 99 is supplied as an argument, or if the object has a precision of greater than 99, the precision is silently reduced to 99.
If the $round argument is true the last digit will be rounded; if the $round argument is false the last digit will be truncated. It is important to note that the last digit (prior to rounding) is guaranteed to be accurate, so rounding will actually reduce the precision, in effect, by one. However, it will capture some of the behavior after the precision limit.
<?php
use Samsara\Fermat\Values\ImmutableNumber;
$twoPiDivThree = Numbers::make2Pi()->divide(3);
$piDivTwo = Numbers::makePi()->divide(2);
echo $twoPiDivThree->tan(14); // Prints: "-1.73205080756888"
echo $twoPiDivThree->tan(14, false); // Prints: "-1.73205080756887"
echo $piDivTwo->tan(); // Prints: "INF"This method applies the cot function to the current Value. If $precision is null, the precision setting of the object is used. If a precision of greater than 99 is supplied as an argument, or if the object has a precision of greater than 99, the precision is silently reduced to 99.
If the $round argument is true the last digit will be rounded; if the $round argument is false the last digit will be truncated. It is important to note that the last digit (prior to rounding) is guaranteed to be accurate, so rounding will actually reduce the precision, in effect, by one. However, it will capture some of the behavior after the precision limit.
<?php
use Samsara\Fermat\Values\ImmutableNumber;
$five = new ImmutableNumber(5);
echo $five->cot(9); // Prints: "-0.295812916"
echo $five->cot(9, false); // Prints: "-0.295812915"