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


7629
7630
# File 'Monkeybrains.rb', line 7629

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


7640
7641
# File 'Monkeybrains.rb', line 7640

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


7651
7652
# File 'Monkeybrains.rb', line 7651

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


7665
7666
# File 'Monkeybrains.rb', line 7665

def atan2(y, x)
end

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

Compute the ceiling of a value.

Parameters:

Returns:

Since:

  • 1.3.0


7675
7676
# File 'Monkeybrains.rb', line 7675

def ceil(x)
end

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

Get the cosine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


7686
7687
# File 'Monkeybrains.rb', line 7686

def cos(x)
end

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

Compute the floor of a value.

Parameters:

Returns:

Since:

  • 1.3.0


7696
7697
# File 'Monkeybrains.rb', line 7696

def floor(x)
end

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

Get natural logarithm of a value

Parameters:

Returns:

Since:

  • 2.3.0


7720
7721
# File 'Monkeybrains.rb', line 7720

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


7709
7710
# File 'Monkeybrains.rb', line 7709

def log(x, base)
end

mean(data) ⇒ Toybox::Lang::Double

Get the arithmetic mean (average) of an array of data.

Parameters:

Returns:

Raises:

Since:

  • 3.1.0


7732
7733
# File 'Monkeybrains.rb', line 7732

def mean(data)
end

mode(data) ⇒ Toybox::Lang::Object

Get the most common value found in an array of data.

Parameters:

Returns:

Raises:

Since:

  • 3.1.0


7742
7743
# File 'Monkeybrains.rb', line 7742

def mode(data)
end

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

Calculate x to the power of y.

Parameters:

Returns:

Since:

  • 1.0.0


7755
7756
# File 'Monkeybrains.rb', line 7755

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


7761
7762
# File 'Monkeybrains.rb', line 7761

def rand()
end

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

Round a value.

Parameters:

Returns:

Since:

  • 1.3.0


7771
7772
# File 'Monkeybrains.rb', line 7771

def round(x)
end

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

Get the sine of an angle.

Parameters:

Returns:

Since:

  • 1.0.0


7782
7783
# File 'Monkeybrains.rb', line 7782

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


7793
7794
# File 'Monkeybrains.rb', line 7793

def sqrt(x)
end

srand(seed) ⇒ Object

Note:

srand() does not return any value.

Seed the random number generator.

Parameters:

Since:

  • 1.0.0


7800
7801
# File 'Monkeybrains.rb', line 7800

def srand(seed)
end

stdev(data, xbar) ⇒ Toybox::Lang::Double

Get the standard deviation of a sample of population data.

Parameters:

Returns:

Raises:

Since:

  • 3.1.0


7814
7815
# File 'Monkeybrains.rb', line 7814

def stdev(data, xbar)
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


7825
7826
# File 'Monkeybrains.rb', line 7825

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


7836
7837
# File 'Monkeybrains.rb', line 7836

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


7847
7848
# File 'Monkeybrains.rb', line 7847

def toRadians(x)
end

variance(data, xbar) ⇒ Toybox::Lang::Double

Get the sample variance of an array of data.

Returns the sample variance with Bessel's correction.

Parameters:

Returns:

Raises:

Since:

  • 3.1.0


7863
7864
# File 'Monkeybrains.rb', line 7863

def variance(data, xbar)
end