Float
The convention is to name the module alias after the file name it is defined in:
import Float "mo:base/Float";
Utility Functions
Function abs
Function sqrt
Function ceil
Function floor
Function trunc
Function nearest
Function copySign
Function min
Function max
Conversion
Function toInt
Function fromInt
Function toText
Function toInt64
Function fromInt64
Comparison
Function equalWithin
Function notEqualWithin
Function less
Function lessOrEqual
Function greater
Function greaterOrEqual
Function compare
Numerical Operations
Function neg
Function add
Function sub
Function mul
Function div
Function rem
Function pow
Mathematical Operations
Function sin
Function cos
Function tan
Function arcsin
Function arccos
Function arctan
Function arctan2
Function exp
Function log
Float.abs
func abs : (x : Float) -> Float
The function abs
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
let pi : Float = -3.14;
Float.abs(pi);
Float.sqrt
func sqrt : (x : Float) -> Float
The function sqrt
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.sqrt(9);
Float.ceil
func ceil : (x : Float) -> Float
The function ceil
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
let pi : Float = 3.14;
Float.ceil(pi);
Float.floor
func floor : (x : Float) -> Float
The function floor
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
let pi : Float = 3.14;
Float.floor(pi);
Float.trunc
func trunc : (x : Float) -> Float
The function trunc
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.trunc(3.98);
Float.nearest
func nearest : (x : Float) -> Float
The function nearest
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.nearest(3.5);
Float.copySign
func copySign : (x : Float) -> Float
The function copySign
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = -3.64;
let b : Float = 2.64;
Float.copySign(a, b);
Float.min
let min : (x : Float, y : Float) -> Float
The function min
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = -3.64;
let b : Float = 2.64;
Float.min(a, b);
Float.max
let max : (x : Float, y : Float) -> Float
The function max
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = -3.64;
let b : Float = 2.64;
Float.max(a, b);
Float.toInt
func toInt : Float -> Int
The function toInt
takes one Float
value and returns an Int
value.
import Float "mo:base/Float";
let pi : Float = 3.14;
Float.toInt(pi);
Float.fromInt
func fromInt : Int -> Float
The function fromInt
takes one Int
value and returns a Float
value.
import Float "mo:base/Float";
let x : Int = -15;
Float.fromInt(x);
Float.toText
func toText : Float -> Text
The function toText
takes one Float
value and returns a Text
value.
import Float "mo:base/Float";
let pi : Float = 3.14;
Float.toText(pi);
Float.toInt64
func toInt64 : Float -> Int64
The function toInt64
takes one Float
value and returns an Int64
value.
import Float "mo:base/Float";
let pi : Float = 3.14;
Float.toInt64(pi);
Float.fromInt64
func fromInt64 : Int64 -> Float
The function fromInt64
takes one Int64
value and returns a Float
value.
import Float "mo:base/Float";
let y : Int64 = -64646464;
Float.fromInt64(y);
Float.equalWithin
func equalWithin(x : Float, y : Float, epsilon : Float) : Bool
The function equalWithin
takes two Float
and one epsilon
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 51.2;
let b : Float = 5.12e1;
let epsilon : Float = 1e-6;
Float.equalWithin(a, b, epsilon)
Float.notEqualWithin
func notEqualWithin(x : Float, y : Float, epsilon : Float) : Bool
The function notEqualWithin
takes two Float
and one epsilon
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 51.2;
let b : Float = 5.12e1;
let epsilon : Float = 1e-6;
Float.notEqualWithin(a, b, epsilon)
Float.less
func less(x : Float, y : Float) : Bool
The function less
takes two Float
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 3.14;
let b : Float = 3.24;
Float.less(a, b);
Float.lessOrEqual
func lessOrEqual(x : Float, y : Float) : Bool
The function lessOrEqual
takes two Float
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 3.14;
let b : Float = 3.24;
Float.lessOrEqual(a, b);
Float.greater
func greater(x : Float, y : Float) : Bool
The function greater
takes two Float
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 5.12;
let b : Float = 3.14;
Float.greater(a, b);
Float.greaterOrEqual
func greaterOrEqual(x : Float, y : Float) : Bool
The function greaterOrEqual
takes two Float
value and returns a Bool
value.
import Float "mo:base/Float";
let a : Float = 5.12;
let b : Float = 3.14;
Float.greaterOrEqual(a, b);
Float.compare
func compare(x : Float, y : Float) : {#less; #equal; #greater}
The function compare
takes two Float
value and returns an Order value.
import Float "mo:base/Float";
let a : Float = 5.12;
let b : Float = 3.14;
Float.compare(a, b);
Float.neg
func neg(x : Float) : Float
The function neg
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.neg(5.12);
Float.add
func add(x : Float, y : Float) : Float
The function add
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 5.50;
let b : Float = 3.50;
Float.add(a, b);
Float.sub
func sub(x : Float, y : Float) : Float
The function sub
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 5.12;
let b : Float = 3.12;
Float.sub(a, b);
Float.mul
func mul(x : Float, y : Float) : Float
The function mul
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 5.25;
let b : Float = 4.00;
Float.mul(a, b);
Float.div
func div(x : Float, y : Float) : Float
The function div
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 6.12;
let b : Float = 3.06;
Float.div(a, b);
Float.rem
func rem(x : Float, y : Float) : Float
The function rem
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 5.12;
let b : Float = 3.12;
Float.rem(a, b);
Float.pow
func pow(x : Float, y : Float) : Float
The function pow
takes two Float
value and returns a Float
value.
import Float "mo:base/Float";
let a : Float = 1.5;
let b : Float = 2.0;
Float.pow(a, b);
Float.sin
func sin : (x : Float) -> Float
The function sin
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.sin(Float.pi / 2);
Float.cos
func cos : (x : Float) -> Float
The function cos
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.cos(0);
Float.tan
func tan : (x : Float) -> Float
The function tan
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.tan(Float.pi / 4);
Float.arcsin
func arcsin : (x : Float) -> Float
The function arcsin
takes one Float
value and returns a Float
value. for more explanation look for official documentation
import Float "mo:base/Float";
Float.arcsin(1.0)
Float.arccos
func arccos : (x : Float) -> Float
The function arccos
takes one Float
value and returns a Float
value. for more explanation look for official documentation
import Float "mo:base/Float";
Float.arccos(1.0)
Float.arctan
func arctan : (x : Float) -> Float
The function arctan
takes one Float
value and returns a Float
value. for more explanation look for official documentation
import Float "mo:base/Float";
Float.arctan(1.0)
Float.arctan2
func arctan2 : (y : Float, x : Float) -> Float
The function arctan2
takes two Float
value and returns a Float
value. for more explanation look for official documentation
import Float "mo:base/Float";
Float.arctan2(4, -3)
Float.exp
func exp : (x : Float) -> Float
The function exp
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
Float.exp(1.0)
Float.log
func log : (x : Float) -> Float
The function log
takes one Float
value and returns a Float
value.
import Float "mo:base/Float";
let exponential : Float = Float.e;
Float.log(exponential)