Module: Toybox::Math

Overview

The Math Module provides various math methods available for use by Apps.

Examples:

Prints the circumference of a circle.

using Toybox.System;
using Toybox.Math;
var r = 5;
var circumference = (2 * Math.PI * r);

System.println(circumference);

Prints the area of a square with Math.pow via direct call.

using Toybox.System;
using Toybox.Math;

System.println(Math.pow(10, 2));

Solves for c using the Pythagorean Theorem and multiple Math API methods.

using Toybox.System;
using Toybox.Math;
var a = 2;
var b = 3;
var c = Math.sqrt((Math.pow(a, 2) + Math.pow(b, 2)));

System.println(c);

Since:

  • 1.0.0

Defined Under Namespace

Classes: Filter, FirFilter, IirFilter

Constant Summary

PI = 3.14159265358979323846

Since:

  • 1.0.0

E = 2.7182818284590452354

Since:

  • 1.0.0

Instance Method Summary collapse

Instance Method Details

acos(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the arc cosine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


6544
6545
# File 'Monkeybrains.rb', line 6544

def acos(x)
end

asin(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the arc sine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


6555
6556
# File 'Monkeybrains.rb', line 6555

def asin(x)
end

atan(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the arc tangent of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


6566
6567
# File 'Monkeybrains.rb', line 6566

def atan(x)
end

atan2(y, x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the arc tangent of y/x in radians.

Parameters:

Returns:

  • (Toybox::Lang::Float, Toybox::Lang::Double)

    The principal arc tangent of y/x, in the interval [-PI..PI] radians, or NaN if invalid

    • Float if both inputs are Number or Float

    • Double if either input is Long or Double

Since:

  • 1.3.0


6580
6581
# File 'Monkeybrains.rb', line 6580

def atan2(y, x)
end

ceil(x) ⇒ Toybox::Lang::Number, ...

Compute the ceiling of a value.

Parameters:

Returns:

Since:

  • 1.3.0


6590
6591
# File 'Monkeybrains.rb', line 6590

def ceil(x)
end

cos(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the cosine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


6601
6602
# File 'Monkeybrains.rb', line 6601

def cos(x)
end

floor(x) ⇒ Toybox::Lang::Number, ...

Compute the floor of a value.

Parameters:

Returns:

Since:

  • 1.3.0


6611
6612
# File 'Monkeybrains.rb', line 6611

def floor(x)
end

ln(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get natural logarithm of a value

Parameters:

Returns:

Since:

  • 2.3.0


6635
6636
# File 'Monkeybrains.rb', line 6635

def ln(x)
end

log(x, base) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get logarithm of a value using the specified base

Parameters:

Returns:

Since:

  • 1.0.0


6624
6625
# File 'Monkeybrains.rb', line 6624

def log(x, base)
end

pow(x, y) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Calculate x to the power of y.

Parameters:

Returns:

Since:

  • 1.0.0


6648
6649
# File 'Monkeybrains.rb', line 6648

def pow(x, y)
end

randToybox::Lang::Number

Returns a pseudo-random Number. Use the srand() function to seed the random number generator.

Returns:

Since:

  • 1.0.0


6654
6655
# File 'Monkeybrains.rb', line 6654

def rand()
end

round(x) ⇒ Toybox::Lang::Number, ...

Round a value.

Parameters:

Returns:

Since:

  • 1.3.0


6664
6665
# File 'Monkeybrains.rb', line 6664

def round(x)
end

sin(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the sine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


6675
6676
# File 'Monkeybrains.rb', line 6675

def sin(x)
end

sqrt(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Calculate the square root of a value.

Parameters:

Returns:

Since:

  • 1.0.0


6686
6687
# File 'Monkeybrains.rb', line 6686

def sqrt(x)
end

srand(seed) ⇒ Object

Note:

srand() does not return any value.

Seed the random number generator.

Parameters:

Since:

  • 1.0.0


6693
6694
# File 'Monkeybrains.rb', line 6693

def srand(seed)
end

tan(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Get the tangent of an angle.

Parameters:

Returns:

  • (Toybox::Lang::Float, Toybox::Lang::Double)

    The tangent value of x in radians Toybox::Lang::Float if input is Toybox::Lang::Number or Toybox::Lang::Float Toybox::Lang::Double if input is Toybox::Lang::Long or Toybox::Lang::Double

Since:

  • 1.0.0


6704
6705
# File 'Monkeybrains.rb', line 6704

def tan(x)
end

toDegrees(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Convert an angle from radians to degrees.

Parameters:

Returns:

Since:

  • 1.3.0


6715
6716
# File 'Monkeybrains.rb', line 6715

def toDegrees(x)
end

toRadians(x) ⇒ Toybox::Lang::Float, Toybox::Lang::Double

Convert an angle from degrees to radians.

Parameters:

Returns:

Since:

  • 1.3.0


6726
6727
# File 'Monkeybrains.rb', line 6726

def toRadians(x)
end