Matematika
paket "matematika";
The matematika
package comes with various mathematical functions and constants. Below is a comprehensive list.
Variables:
Functions:
- apsolutnaVrijednost
- arccos
- arcsin
- sin
- cos
- tg
- arctg
- korijen
- eNa
- ln
- log
- log10
- log2
- max
- min
- zaokruzi
- kubniKorijen
- uStepenima
Variables
Constant pi
Pi is the mathematical constant that represents the ratio of a circle’s circumference to its diameter.
ispis(pi);
Output:
3.141592653589793
Constant e
e
is the mathematical constant known as Euler’s number. It is the base of the natural logarithm.
ispis(e);
Output:
2.718281828459045
Infinity
Bosscript has separate constants for positive and negative infinity.
ispis(beskonacno); ispis(minusBeskonacno);
ispis(apsolutnaVrijednost(22)); ispis(apsolutnaVrijednost(-22)); ispis(apsolutnaVrijednost(0));
Output: 22 22 0
arccos
The arccos
function returns the arc cosine of a provided broj
.
- takes: x -
broj
- returns: an angle in the range from 0.0 to PI radians (
broj
) - special cases
- returns
NaN
ifx
is greater than 1 or lower than -1
- returns
ispis(arccos(1)); ispis(arccos(0)); ispis(arccos(100));
Output: 0 1.5707963267948966 "comment">// π/2 NaN
arcsin
The arcsin
function returns the arc sine of a provided broj
.
- takes: x -
broj
- returns: an angle in the range from -PI/2 to PI/2 radians (
broj
) - special cases
- returns
NaN
ifx
is greater than 1 or lower than -1
- returns
ispis(arcsin(0)); ispis(arcsin(1)); ispis(arcsin(100));
Output: 0 1.5707963267948966 "comment">// π/2 NaN
sin
The sin
function returns the sine of a provided broj
.
- takes: x - angle expressed in degrees (
broj
) - returns: sine of the provided angle (
broj
) - special cases
- returns
NaN
ifx
is NaN or Infinity
- returns
ispis(sin(90)); ispis(sin(0)); ispis(sin(45));
Output: 1 0 0.7071067811865475
cos
The cos
function returns the cosine of a provided broj
.
- takes: x - angle expressed in degrees (
broj
) - returns: cosine of the provided angle (
broj
) - special cases
- returns
NaN
ifx
is NaN or Infinity
- returns
ispis(cos(90)); ispis(cos(0)); ispis(cos(45));
Output: 0 1 0.7071067811865476
tg
The tg
function returns the tangent of a provided broj
.
- takes: x - angle expressed in degrees (
broj
) - returns: sine of the provided angle (
broj
) - special cases
- returns
NaN
ifx
is NaN or Infinity
- returns
ispis(tg(90)); ispis(tg(0)); ispis(tg(45));
Output: 1.633123935319537E16 "comment">// Actually undefined 0 1
arctg
The arctg
function returns the arc tangent of a provided broj
.
- takes: x -
broj
- returns: an angle in the range from -PI/2 to PI/2 radians (
broj
) - special cases
- returns
NaN
ifx
isNaN
- returns
ispis(arctg(0)); ispis(arctg(1)); ispis(arctg(100));
Output: 0 0.7853981633974483 1.5607966601082315
korijen
The korijen
function returns the square root of a provided broj
.
- takes: x -
broj
- returns: square root of provided number (
broj
) - special cases:
- throws Exception if
x
is a negative number
- throws Exception if
ispis(korijen(144)); ispis(korijen(2)); ispis(korijen(0));
Output: 12 1.4142135623730951 0
ispis(korijen(-1));
Error: Square root cannot be calculated for negative numbers. Value -1 is invalid.
eNa
The eNa
function returns Euler’s number e
raised to the power of the provided broj
- takes: x -
broj
- returns: ex (
broj
) - special cases:
- when
x
isNaN
, returnsNaN
- when
x
is Infinity, returns Infinity - when
x
is -Infinity, returns 0
- when
ispis(eNa(2)); ispis(eNa(-1)); ispis(eNa(0));
Output: 7.38905609893065 0.36787944117144233 1
ln
The ln
function returns the natural logarithm of the provided broj
.
- takes: x -
broj
- returns: natural log of
x
(broj
) - special cases:
- throws Exception when
x
< 0.0 - ln(NaN) is NaN
- ln(Infinity) is Infinity
- ln(0.0) is -Infinity
- throws Exception when
ispis(ln(14)); ispis(ln(32)); ispis(ln(e));
Output: 2.6390573296152584 3.4657359027997265 1
ispis(ln(-1));
Error: Cannot calculate ln of -1.0: Value must be a positive number
log
The log
function computes the logarithm of the value x
to the given base b
.
- takes: x - number (
broj
), b - base (broj
) - returns: log base
b
ofx
- special cases:
- log(x, b) is NaN if either x or b are NaN
- log(x, b) is NaN when x < 0 or b <= 0 or b == 1.0
- log(Infinity, Infinity) is NaN
- log(Infinity, b) is Infinity for b > 1 and -Infinity for b < 1
- log(0.0, b) is -Infinity for b > 1 and Infinity for b > 1
ispis(log(45, 4)); ispis(log(45, 2)); ispis(log(45, 5)); ispis(log(45, 1));
Output: 2.7459265481648374 5.491853096329675 2.3652123889719707 NaN
log10
The log10
function computes the common logarithm (base 10) of the provided broj
.
- takes: x - number (
broj
) - returns: log base 10 of
x
- special cases:
- returns NaN if x is a negative number
ispis(log10(142)); ispis(log10(12)); ispis(log10(-50));
Output: 2.1522883443830563 1.0791812460476249 NaN
log2
The log2
function computes the binary logarithm (base 2) of the provided broj
.
- takes: x - number (
broj
) - returns: log base 2 of
x
- special cases:
- returns NaN if x is a negative number
ispis(log2(142)); ispis(log2(12)); ispis(log2(-50));
Output: 7.149747119504682 3.5849625007211565 NaN
max
The max
function returns the greater of the two provided broj
values.
- takes: x (
broj
), y (broj
) - returns: the greater of
x
andy
- special cases:
- returns NaN if either
x
ory
is NaN
- returns NaN if either
ispis(max(2, 3)); ispis(max(2, -3)); ispis(max(1, 1));
Output: 33 2 1
min
The min
function returns the smaller of the two provided broj
values.
- takes: x (
broj
), y (broj
) - returns: the smaller of
x
andy
- special cases:
- returns NaN if either
x
ory
is NaN
- returns NaN if either
ispis(min(2, 33)); ispis(min(-2, 33)); ispis(min(2, 2));
Output: 2 -2 2
zaokruzi
The zaokruzi
function rounds the given value x towards the closest integer with ties rounded towards even integer.
- takes: x - number (
broj
) - returns:
x
rounded to the closest integer - special cases:
- returns
x
whenx
is NaN, Infinity, or already an Integer
- returns
ispis(zaokruzi(33.33333333)); ispis(zaokruzi(1.25)); ispis(zaokruzi(3.55));
Output: 33 1 4
kubniKorijen
The kubniKorijen
function returns the cubic root of a provided broj
.
- takes: x -
broj
- returns: cubic root of provided number (
broj
) - special cases:
- If x is NaN, then the result is NaN.
- If x is Infinity, then the result is Infinity
ispis(kubniKorijen(144)); ispis(kubniKorijen(2)); ispis(kubniKorijen(0));
Output: 5.241482788417793 1.2599210498948732 0
uStepenima
The uStepenima
function converts an angle measured in radians to an approximately equivalent angle measured in degrees.
- takes: x - angle expressed in radians
broj
- returns: x expressed in degrees (
broj
) - special cases: none
"comment">// Convert π/2 radians to degrees ispis(uStepenima(1.5707963267948966));
Output:
90