Module Relude_Float
Relude.Float contains typeclass instances and utility functions for the float type.
let eq: float => float => bool;Float.eqindicates whether the two provided floats are exactly equal.
module Eq: BsBastet.Interface.EQ with type Eq.t = float;let nan: float;Float.nanis the floating point value representing "not a number." This may be used for mathematical operations that do not result in a real number, such as0.0 /. 0.0andsqrt(-2).Note that two
Float.nanvalues are not equal to each other (and in fact,Float.nanis not equal to itself). To check fornan, useFloat.isNaN.
let pow: float => float => float;Float.powraises the first number to the power of the second number.Float.pow(2.0, 4.0) == 16.0; Float.pow(3.0, 2.0) == 9.0; Float.(pow(-2.0, (0.333333)) |> isNaN) == true;
let sqrt: float => float;Float.sqrtdetermines the square root of the given float. The square root of negative numbers isnan.
let bottom: float;Float.bottomis the minimum float value. Note that when using Bucklescript, this value is hard-coded and is not necessarily equal toNumber.MIN_VALUEin JS.
let isNaN: float => bool;Float.isNaNdetermines whether the provided floating point number isnan. NaN values are never equal to other numeric values, including other NaN values. This means that the intuitivemyValue == nanis not sufficient for determining whether a value is NaN.Float.isNaN(3.14) == false; Float.isNaN(infinity) == false; Float.isNaN(nan) == true;
module Ord: BsBastet.Interface.ORD with type Ord.t = float;include { ... };
let compareWithConversion: ('b => Ord.t) => Relude_Ord.compare('b);let compareReversed: Relude_Ord.compare(Ord.t);
module OrdReversed: { ... };let compareAsInt: Ord.t => Ord.t => int;let min: Ord.t => Ord.t => Ord.t;let max: Ord.t => Ord.t => Ord.t;let lessThan: Ord.t => Ord.t => bool;let lt: Ord.t => Ord.t => bool;let lessThanOrEq: Ord.t => Ord.t => bool;let lte: Ord.t => Ord.t => bool;let greaterThan: Ord.t => Ord.t => bool;let gt: Ord.t => Ord.t => bool;let greaterThanOrEq: Ord.t => Ord.t => bool;let gte: Ord.t => Ord.t => bool;let clamp: min:Ord.t => max:Ord.t => Ord.t => Ord.t;let between: min:Ord.t => max:Ord.t => Ord.t => bool;
module OrdRingExtensions: (R: { ... }) => { ... };module OrdNamed: { ... };module Semiring: BsBastet.Interface.SEMIRING with type Semiring.t = float;include { ... };
module Ring: BsBastet.Interface.RING with type Ring.t = float;module EuclideanRing: BsBastet.Interface.EUCLIDEAN_RING with type EuclideanRing.t = float;let approximatelyEqual: tolerance:float => float => float => bool;Float.approximatelyEqualreturnstrueif the two provided floats are within~toleranceof one another.If a negative
~toleranceis provided, the returned value will always befalse.Float.approximatelyEqual(~tolerance=0.01, 1.500, 1.495) == true; Float.approximatelyEqual(~tolerance=0.01, 1.500, 1.49) == false;
let toInt: float => int;Float.toIntconverts a float to an int by dropping the fractional part. Removing the portion after the decimal is distinct fromroundorfloor.Floats that can't be represented as an integer (e.g.
infinity,nan) will return0. Because the range of ints is smaller (32-bit) than floats, this operation can lead to int overflows.Float.toInt(3.1415) == 3; Float.toInt(-2.999) == -2; Float.toInt(Float.infinity) == 0; Float.toInt(12345678901.0) == -539222987;
let fromInt: int => float;Float.fromIntconverts an int (e.g.1) to its floating-point representation (1.0).
let fractionalPart: float => Ring.t;Float.fractionalPartreturns only the decimal portion as a positive floating point number, with the whole-number portion set to 0.Note that the returned value is subject to floating point rounding errors and probably won't be exactly equal to the fractional part of the original number.
Float.fractionalPart(3.141592) ~= 0.141592; Float.fractionalPart(-12.3456) ~= 0.3456;
let floor: float => float;Float.floorrounds a floating point number to the nearest lower whole number.
let floorAsInt: float => int;Float.floorAsIntrounds a floating point number to the nearest lower integer.
let ceil: float => float;Float.ceilrounds a floating point number to the nearest higher whole number.
let ceilAsInt: float => int;Float.ceilAsIntrounds a floating point number to the nearest higher integer.
let roundAsInt: float => int;Float.roundAsIntrounds a floating point number to the nearest integer.
let toPrecision: decimals:int => float => float;Float.toPrecisiondrops decimals so that the given float has no more than the requested number of decimals.Float.toPrecision(~decimals=2, 3.141592) == 3.14; Float.toPrecision(~decimals=4, -4.99999999999) == -4.9999;
let show: float => string;Float.showreturns the string representation ofx.Note that because there are multiple ways to represent floats in source code, the output returned by
showmay not match the literal float syntax provided to the function.Float.show(3.49) == "3.49"; Float.show(7.0000) == "7"; Float.show(1.0e+03) == "1000";
let toString: float => string;Float.toStringis an alias forshow.
module Show: BsBastet.Interface.SHOW with type Show.t = float;let fromString: string => option(float);Float.fromStringattempts to parse the provided string, returningSomefloat if the input string is a valid floating point number orNoneotherwise.Float.fromString("1000.0") == Some(1000.0); Float.fromString("-5.25E2") == Some(-525.0); Float.fromString("3.4.5") == None;
module Additive: { ... };module Multiplicative: { ... };module Subtractive: { ... };module Divisive: { ... };module Infix: { ... };