Module Prelude.Math

Math functions from java.lang.Math. Many of those functions are overloaded for Float and Double, so we introduce a type class Floating to avoid overloading issues.

For example

 f x = 2 * sqrt x

would give a type error, because the compiler wouldn't know whether to use

 sqrt :: Float  -> Double

or

 sqrt :: Double -> Double

Note that many functions return Double, no matter if the argument was Double or Float.

Imports

Table of Content

Definitions

random()IO Double
native java.lang.Math.random

Returns a Double with a positive sign, greater than or equal to 0.0 and less than 1.0.

sqrNum a ⇒ a → a

square

class (Eq r, Ord r, Num r, Real r) ⇒ Floating r

Known Instances

Double, Float

Member Functions

acosFloating r ⇒ r → Double

Returns the arc cosine of a value; the returned angle is in the range 0.0 through Floating.pi.

acoshFloating r ⇒ r → Double

Inverse hyperbolic function for Floating.cosh

asinFloating r ⇒ r → Double

Returns the arc sine of a value; the returned angle is in the range -Floating.pi/2 through Floating.pi/2.

asinhFloating r ⇒ r → Double

Inverse hyperbolic function for Floating.sinh

atanFloating r ⇒ r → Double

Returns the arc tangent of a value; the returned angle is in the range -Floating.pi/2 through Floating.pi/2.

atan2Floating r ⇒ r → r → Double

Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).

atanhFloating r ⇒ r → Double

Inverse hyperbolic function for Floating.tanh

cbrtFloating r ⇒ r → Double

Returns the cube root of a value.

ceilFloating r ⇒ r → Double

Returns the smallest (closest to negative infinity) value that is greater than or equal to the argument and is equal to a mathematical integer.

copySignFloating r ⇒ r → r → r

Returns the first argument with the sign of the second argument.

cosFloating r ⇒ r → Double

Returns the trigonometric cosine of an angle.

coshFloating r ⇒ r → Double

Returns the hyperbolic cosine of a floating point value.

eFloating r ⇒ r

The value that is closer than any other to e, the base of the natural logarithms.

expFloating r ⇒ r → Double

Returns Euler's number Floating.e raised to the power of a floating-point value.

expm1Floating r ⇒ r → Double

Returns e^x -1.

floorFloating r ⇒ r → Double

Returns the largest (closest to positive infinity) value that is less than or equal to the argument and is equal to a mathematical integer.

Special cases:

  • If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
getExponentFloating r ⇒ r → Int

Returns the unbiased exponent used in the representation of a floating point number.

hypotFloating r ⇒ r → r → Double

Returns Floating.sqrt (x² + y²) without intermediate overflow or underflow.

ieeeRemainderFloating r ⇒ r → r → Double

Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.

logFloating r ⇒ r → Double

Returns the natural logarithm (base Floating.e) of a value.

log10Floating r ⇒ r → Double

Returns the base 10 logarithm of a value.

log1pFloating r ⇒ r → Double

Returns the natural logarithm of the sum of the argument and 1.

logBaseFloating r ⇒ r → r → Double

Returns the logarithm of the second argument to the base given by the first argument.

nextAfterFloating r ⇒ r → r → Double

Returns the floating-point number adjacent to the first argument in the direction of the second argument.

nextUpFloating r ⇒ r → r

Returns the floating-point value adjacent to the argument in the direction of positive infinity.

piFloating r ⇒ r

The value that is closer than any other to pi, the ratio of the circumference of a circle to its diameter.

powFloating r ⇒ r → r → Double
infixr  15

Returns the value of the first argument raised to the power of the second argument.

rintFloating r ⇒ r → Double

Returns the double value that is closest in value to the argument and is equal to a mathematical integer.

roundFloating r ⇒ r → Long

Returns the closest Long to the argument, with ties rounding up.

scalbFloating r ⇒ r → Int → r
 scalb d scaleFactor

Return d * 2^scaleFactor rounded as if performed by a single correctly rounded floating-point multiply.

signumFloating r ⇒ r → r

Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.

sinFloating r ⇒ r → Double

Returns the trigonometric sine of an angle.

sinhFloating r ⇒ r → Double

Returns the hyperbolic sine of a value.

sqrtFloating r ⇒ r → Double

Returns the correctly rounded positive square root of a value.

tanFloating r ⇒ r → Double

Returns the trigonometric tangent of an angle.

tanhFloating r ⇒ r → Double

Returns the hyperbolic tangent of a floating point value.

toDegreesFloating r ⇒ r → Double

Converts an angle measured in radians to an approximately equivalent angle measured in degrees.

toRadiansFloating r ⇒ r → Double

Converts an angle measured in degrees to an approximately equivalent angle measured in radians.

ulpFloating r ⇒ r → r

Returns the size of an ulp of the argument.

Instances

instance Floating Double

Member Functions

acosDoubleDouble
acoshDoubleDouble
asinDoubleDouble
asinhDoubleDouble
atanDoubleDouble
atan2DoubleDoubleDouble
atanhDoubleDouble
cbrtDoubleDouble
ceilDoubleDouble
copySignDoubleDoubleDouble
cosDoubleDouble
coshDoubleDouble
eDouble
expDoubleDouble
expm1DoubleDouble
floorDoubleDouble
getExponentDoubleInt
hypotDoubleDoubleDouble
ieeeRemainderDoubleDoubleDouble
logDoubleDouble
log10DoubleDouble
log1pDoubleDouble
logBaseDoubleDoubleDouble

inherited from Floating.logBase

nextAfterDoubleDoubleDouble
nextUpDoubleDouble
piDouble
powDoubleDoubleDouble
infixr  15
rintDoubleDouble
roundDoubleLong
scalbDoubleIntDouble
signumDoubleDouble
sinDoubleDouble
sinhDoubleDouble
sqrtDoubleDouble
tanDoubleDouble
tanhDoubleDouble
toDegreesDoubleDouble
toRadiansDoubleDouble
ulpDoubleDouble
instance Floating Float

Member Functions

acosFloatDouble
acoshFloatDouble
asinFloatDouble
asinhFloatDouble
atanFloatDouble
atan2FloatFloatDouble
atanhFloatDouble
cbrtFloatDouble
ceilFloatDouble
copySignFloatFloatFloat
cosFloatDouble
coshFloatDouble
eFloat
expFloatDouble
expm1FloatDouble
floorFloatDouble
getExponentFloatInt
hypotFloatFloatDouble
ieeeRemainderFloatFloatDouble
logFloatDouble
log10FloatDouble
log1pFloatDouble
logBaseFloatFloatDouble

inherited from Floating.logBase

nextAfterFloatFloatDouble
nextUpFloatFloat
piFloat
powFloatFloatDouble
infixr  15
rintFloatDouble
roundFloatLong
scalbFloatIntFloat
signumFloatFloat
sinFloatDouble
sinhFloatDouble
sqrtFloatDouble
tanFloatDouble
tanhFloatDouble
toDegreesFloatDouble
toRadiansFloatDouble
ulpFloatFloat

Functions and Values by Type

()IO Double

random

DoubleDoubleDouble

Floating_Double.pow, Floating_Double.nextAfter, Floating_Double.ieeeRemainder, Floating_Double.logBase, Floating_Double.atan2, Floating_Double.copySign, Floating_Double.hypot

DoubleIntDouble

Floating_Double.scalb

DoubleDouble

Floating_Double.ulp, Floating_Double.tanh, Floating_Double.toDegrees, Floating_Double.toRadians, Floating_Double.sqrt, Floating_Double.sin, Floating_Double.sinh, Floating_Double.tan, Floating_Double.rint, Floating_Double.nextUp, Floating_Double.log1p, Floating_Double.log, Floating_Double.log10, Floating_Double.signum, Floating_Double.expm1, Floating_Double.floor, Floating_Double.cos, Floating_Double.cosh, Floating_Double.exp, Floating_Double.ceil, Floating_Double.atanh, Floating_Double.cbrt, Floating_Double.asin, Floating_Double.asinh, Floating_Double.acos, Floating_Double.acosh, Floating_Double.atan

DoubleInt

Floating_Double.getExponent

DoubleLong

Floating_Double.round

FloatFloatDouble

Floating_Float.pow, Floating_Float.nextAfter, Floating_Float.ieeeRemainder, Floating_Float.logBase, Floating_Float.atan2, Floating_Float.hypot

FloatFloatFloat

Floating_Float.copySign

FloatIntFloat

Floating_Float.scalb

FloatDouble

Floating_Float.tanh, Floating_Float.toDegrees, Floating_Float.toRadians, Floating_Float.sqrt, Floating_Float.sin, Floating_Float.sinh, Floating_Float.tan, Floating_Float.rint, Floating_Float.log1p, Floating_Float.log, Floating_Float.log10, Floating_Float.expm1, Floating_Float.floor, Floating_Float.cos, Floating_Float.cosh, Floating_Float.exp, Floating_Float.ceil, Floating_Float.atanh, Floating_Float.cbrt, Floating_Float.asin, Floating_Float.asinh, Floating_Float.acos, Floating_Float.acosh, Floating_Float.atan

FloatFloat

Floating_Float.ulp, Floating_Float.nextUp, Floating_Float.signum

FloatInt

Floating_Float.getExponent

FloatLong

Floating_Float.round

Double

Floating_Double.pi, Floating_Double.e

Float

Floating_Float.pi, Floating_Float.e

Floating r ⇒ r → Int → r

Floating.scalb

Floating r ⇒ r → r → Double

Floating.pow, Floating.logBase, Floating.nextAfter, Floating.ieeeRemainder, Floating.hypot, Floating.atan2

Floating r ⇒ r → r → r

Floating.copySign

Floating r ⇒ r → Double

Floating.toDegrees, Floating.toRadians, Floating.tan, Floating.sqrt, Floating.tanh, Floating.sin, Floating.rint, Floating.sinh, Floating.log10, Floating.log1p, Floating.floor, Floating.exp, Floating.expm1, Floating.log, Floating.cos, Floating.ceil, Floating.cbrt, Floating.atan, Floating.asin, Floating.acos, Floating.acosh, Floating.asinh, Floating.atanh, Floating.cosh

Floating r ⇒ r → Int

Floating.getExponent

Floating r ⇒ r → Long

Floating.round

Floating r ⇒ r → r

Floating.ulp, Floating.signum, Floating.nextUp

Num a ⇒ a → a

sqr

Floating r ⇒ r

Floating.pi, Floating.e

Valid HTML 4.01 Strict