DEV Community

Kray-G
Kray-G

Posted on

Kinx Library - Math

Hello, everybody!

The script language Kinx is published with the concept of Looks like JavaScript, Feels like Ruby, Stable like AC/DC(?).

This time it is Math.

Math is a library for mathematics. The same methods are bound to the special object of Integer and Double, so you don't have to use Math instead of those. For example, you can use;

var a = 2.pow(10);     // Math.pow(2, 10)   => 1024
var b = 2.0.pow(10);   // Math.pow(2.0, 10) => 1024
var c = (-10).abs();   // Math.abs(-10)     => 10
Enter fullscreen mode Exit fullscreen mode

As an unary minus is lower priority than the function call, you need parentheses for -10 above. You can also use random() with the receiver of Integer or Double, but the receiver does not mean anything.

var a = 1000.random(); // 1000 is nothing to mean.
var b = 10.0.random(); // 10.0 is nothing to mean.
var c = Math.random(); // Normal.
Enter fullscreen mode Exit fullscreen mode

About the special methods or special objects, see Kinx Library - String.

Math

Here are methods of Math.
By the way, the first argument is x and the second argument is y below.

Method Meaning
Math.sin(dbl) $$\sin x$$
Math.cos(dbl) $$\cos x$$
Math.tan(dbl) $$\tan x$$
Math.asin(dbl) $$\theta$$ for $$\sin \theta=x$$
Math.acos(dbl) $$\theta$$ for $$\cos \theta=x$$
Math.atan(dbl) $$\theta$$ for $$\tan \theta=x$$
Math.atan2(dbl, dbl) the angle between the positive x axis and the ray to the point $$(x, y) \neq (0, 0)$$
Math.sinh(dbl) $$\sinh x$$
Math.cosh(dbl) $$\cosh x$$
Math.tanh(dbl) $$\tanh x$$
Math.exp(dbl) $$e^x$$
Math.ldexp(dbl, int) $$x \times 2^y$$
Math.log(dbl) $$\log_e x$$
Math.log10(dbl) $$\log_{10} x$$
Math.pow(dbl, dbl) $$x^y$$
Math.sqrt(dbl) $$\sqrt x$$
Math.ceil(dbl) Minimum value of integer over $$x$$ by Double
Math.floor(dbl) Maximum value of integer under $$x$$ by Double
Math.fmod(dbl, dbl) Floating point remainder for $$x \div y$$
Math.abs(dbl) Absolute value of $$x$$ by Double
Math.random() Random value between $$0 \leq r < 1$$

Look at above with LaTeX in your brain...

Conclusion

As I wrote at the top of this article, you can use the methods for Integer or Double value directly, so I think you do not have to use it via Math object.

See you next time.

Top comments (0)