Provided by: ocaml-man_4.08.1-8_all

**NAME**

Float - Floating-point arithmetic

**Module**

Module Float

**Documentation**

ModuleFloat:sigendFloating-pointarithmeticOCaml's floating-point numbers follow the IEEE 754 standard, using double precision (64 bits) numbers. Floating-point operations never raise an exception on overflow, underflow, division by zero, etc. Instead, special IEEE numbers are returned as appropriate, such asinfinityfor1.0/.0.0,neg_infinityfor-1.0/.0.0, andnan('not a number') for0.0/.0.0. These special numbers then propagate through floating-point computations as expected: for instance,1.0/.infinityis0.0, and any arithmetic operation withnanas argument returnsnanas result.Since4.07.0valzero:floatThe floating point 0.Since4.08.0valone:floatThe floating-point 1.Since4.08.0valminus_one:floatThe floating-point -1.Since4.08.0valneg:float->floatUnary negation.valadd:float->float->floatFloating-point addition.valsub:float->float->floatFloating-point subtraction.valmul:float->float->floatFloating-point multiplication.valdiv:float->float->floatFloating-point division.valfma:float->float->float->floatfmaxyzreturnsx*y+z, with a best effort for computing this expression with a single rounding, using either hardware instructions (providing full IEEE compliance) or a software emulation. Note: since software emulation of the fma is costly, make sure that you are using hardware fma support if performance matters.Since4.08.0valrem:float->float->floatremabreturns the remainder ofawith respect tob. The returned value isa-.n*.b, wherenis the quotienta/.brounded towards zero to an integer.valsucc:float->floatsuccxreturns the floating point number right afterxi.e., the smallest floating-point number greater thanx. See alsoFloat.next_after.Since4.08.0valpred:float->floatpredxreturns the floating-point number right beforexi.e., the greatest floating-point number smaller thanx. See alsoFloat.next_after.Since4.08.0valabs:float->floatabsfreturns the absolute value off.valinfinity:floatPositive infinity.valneg_infinity:floatNegative infinity.valnan:floatA special floating-point value denoting the result of an undefined operation such as0.0/.0.0. Stands for 'not a number'. Any floating-point operation withnanas argument returnsnanas result. As for floating-point comparisons,=,<,<=,>and>=returnfalseand<>returnstrueif one or both of their arguments isnan.valpi:floatThe constant pi.valmax_float:floatThe largest positive finite value of typefloat.valmin_float:floatThe smallest positive, non-zero, non-denormalized value of typefloat.valepsilon:floatThe difference between1.0and the smallest exactly representable floating-point number greater than1.0.valis_finite:float->boolis_finitexistrueiffxis finite i.e., not infinite and notFloat.nan.Since4.08.0valis_infinite:float->boolis_infinitexistrueiffxisFloat.infinityorFloat.neg_infinity.Since4.08.0valis_nan:float->boolis_nanxistrueiffxis not a number (seeFloat.nan).Since4.08.0valis_integer:float->boolis_integerxistrueiffxis an integer.Since4.08.0valof_int:int->floatConvert an integer to floating-point.valto_int:float->intTruncate the given floating-point number to an integer. The result is unspecified if the argument isnanor falls outside the range of representable integers.valof_string:string->floatConvert the given string to a float. The string is read in decimal (by default) or in hexadecimal (marked by0xor0X). The format of decimal floating-point numbers is[-]dd.ddd(e|E)[+|-]dd, wheredstands for a decimal digit. The format of hexadecimal floating-point numbers is[-]0(x|X)hh.hhh(p|P)[+|-]dd, wherehstands for an hexadecimal digit anddfor a decimal digit. In both cases, at least one of the integer and fractional parts must be given; the exponent part is optional. The_(underscore) character can appear anywhere in the string and is ignored. Depending on the execution platforms, other representations of floating-point numbers can be accepted, but should not be relied upon. RaiseFailurefloat_of_stringif the given string is not a valid representation of a float.valof_string_opt:string->floatoptionSame asof_string, but returnsNoneinstead of raising.valto_string:float->stringReturn the string representation of a floating-point number.typefpclass=fpclass= | FP_normal (* Normal number, none of the below *) | FP_subnormal (* Number very close to 0.0, has reduced precision *) | FP_zero (* Number is 0.0 or -0.0 *) | FP_infinite (* Number is positive or negative infinity *) | FP_nan (* Not a number: result of an undefined operation *) The five classes of floating-point numbers, as determined by theFloat.classify_floatfunction.valclassify_float:float->fpclassReturn the class of the given floating-point number: normal, subnormal, zero, infinite, or not a number.valpow:float->float->floatExponentiation.valsqrt:float->floatSquare root.valexp:float->floatExponential.vallog:float->floatNatural logarithm.vallog10:float->floatBase 10 logarithm.valexpm1:float->floatexpm1xcomputesexpx-.1.0, giving numerically-accurate results even ifxis close to0.0.vallog1p:float->floatlog1pxcomputeslog(1.0+.x)(natural logarithm), giving numerically-accurate results even ifxis close to0.0.valcos:float->floatCosine. Argument is in radians.valsin:float->floatSine. Argument is in radians.valtan:float->floatTangent. Argument is in radians.valacos:float->floatArc cosine. The argument must fall within the range[-1.0,1.0]. Result is in radians and is between0.0andpi.valasin:float->floatArc sine. The argument must fall within the range[-1.0,1.0]. Result is in radians and is between-pi/2andpi/2.valatan:float->floatArc tangent. Result is in radians and is between-pi/2andpi/2.valatan2:float->float->floatatan2yxreturns the arc tangent ofy/.x. The signs ofxandyare used to determine the quadrant of the result. Result is in radians and is between-piandpi.valhypot:float->float->floathypotxyreturnssqrt(x*.x+y*.y), that is, the length of the hypotenuse of a right-angled triangle with sides of lengthxandy, or, equivalently, the distance of the point(x,y)to origin. If one ofxoryis infinite, returnsinfinityeven if the other isnan.valcosh:float->floatHyperbolic cosine. Argument is in radians.valsinh:float->floatHyperbolic sine. Argument is in radians.valtanh:float->floatHyperbolic tangent. Argument is in radians.valtrunc:float->floattruncxroundsxto the nearest integer whose absolute value is less than or equal tox.Since4.08.0valround:float->floatroundxroundsxto the nearest integer with ties (fractional values of 0.5) rounded away from zero, regardless of the current rounding direction. Ifxis an integer,+0.,-0.,nan, or infinite,xitself is returned.Since4.08.0valceil:float->floatRound above to an integer value.ceilfreturns the least integer value greater than or equal tof. The result is returned as a float.valfloor:float->floatRound below to an integer value.floorfreturns the greatest integer value less than or equal tof. The result is returned as a float.valnext_after:float->float->floatnext_afterxyreturns the next representable floating-point value followingxin the direction ofy. More precisely, ifyis greater (resp. less) thanx, it returns the smallest (resp. largest) representable number greater (resp. less) thanx. Ifxequalsy, the function returnsy. Ifxoryisnan, ananis returned. Note thatnext_aftermax_floatinfinity=infinityand thatnext_after0.infinityis the smallest denormalized positive number. Ifxis the smallest denormalized positive number,next_afterx0.=0.Since4.08.0valcopy_sign:float->float->floatcopy_signxyreturns a float whose absolute value is that ofxand whose sign is that ofy. Ifxisnan, returnsnan. Ifyisnan, returns eitherxor-.x, but it is not specified which.valsign_bit:float->boolsign_bitxistrueiff the sign bit ofxis set. For examplesign_bit1.andsignbit0.arefalsewhilesign_bit(-1.)andsign_bit(-0.)aretrue.Since4.08.0valfrexp:float->float*intfrexpfreturns the pair of the significant and the exponent off. Whenfis zero, the significantxand the exponentnoffare equal to zero. Whenfis non-zero, they are defined byf=x*.2**nand0.5<=x<1.0.valldexp:float->int->floatldexpxnreturnsx*.2**n.valmodf:float->float*floatmodffreturns the pair of the fractional and integral part off.typet=floatAn alias for the type of floating-point numbers.valcompare:t->t->intcomparexyreturns0ifxis equal toy, a negative integer ifxis less thany, and a positive integer ifxis greater thany.comparetreatsnanas equal to itself and less than any other float value. This treatment ofnanensures thatcomparedefines a total ordering relation.valequal:t->t->boolThe equal function for floating-point numbers, compared usingFloat.compare.valmin:t->t->tminxyreturns the minimum ofxandy. It returnsnanwhenxoryisnan. Moreovermin(-0.)(+0.)=-0.Since4.08.0valmax:float->float->floatmaxxyreturns the maximum ofxandy. It returnsnanwhenxoryisnan. Moreovermax(-0.)(+0.)=+0.Since4.08.0valmin_max:float->float->float*floatmin_maxxyis(minxy,maxxy), just more efficient.Since4.08.0valmin_num:t->t->tmin_numxyreturns the minimum ofxandytreatingnanas missing values. If bothxandyarenan,nanis returned. Moreovermin_num(-0.)(+0.)=-0.Since4.08.0valmax_num:t->t->tmax_numxyreturns the maximum ofxandytreatingnanas missing values. If bothxandyarenannanis returned. Moreovermax_num(-0.)(+0.)=+0.Since4.08.0valmin_max_num:float->float->float*floatmin_max_numxyis(min_numxy,max_numxy), just more efficient. Note that in particularmin_max_numxnan=(x,x)andmin_max_numnany=(y,y).Since4.08.0valhash:t->intThe hash function for floating-point numbers.moduleArray:sigendmoduleArrayLabels:sigend