Numbers handling - Petewg/harbour-core GitHub Wiki
Numbers handling functions are those that receive a numeric argument, for their main parameter, and do things (such as calculations, transforms or some other kind of processing) with this numeric value.
-
Abs(
<nExp>) β nPositive
returns the absolute value of the passed argument. The result is always greater than or equal to0(zero). -
Exp(
<nExponent>) β nAntilogarithm
returns a numeric value that is equivalent to the value oferaised to the specified power. The maximum value of<nExponent>is46otherwise a numeric overflow occurs. It's the inverse function of 'LOG()'. -
hb_ntoc(
<nValue>, [nDecs]) β cValue
This function converts the given numeric value to a string value, while (trying to) keep all or at leastnDecssignificant digits in double numbers, unless<nDecs>is lesser than actual decimal digits of<nValue>, in which case the result will be rounded.
SET DECIMAL setting has no effect on the returned value (ignored), which means that, unlike f.e. Str(), all non-sginficant digits (e.g.: trailing decimal zeros) will be removed. Likewise, all leading empty spaces will be trimmed.
Returns stringified value of<nValue>, preserving all (or at least<nDecs>) significant digits, if any.
Interestingly, if<nValue>is NIL or not numeric, this function will return a null string and, unlike Str(), will NOT cause an RTE.
NOTE: new function, available after 2016-06-20 21:59 UTC+0200 commit (it is not available in earlier versions). -
hb_ntos(
<nValue>) β cSstring
converts any numeric value to a string, trimming all the surplus spaces, equivalent to 'LTrim(Str( nNumber ))'.
Returns converted value ornullstring, if the nValue passed is not numeric (or not passed). -
hb_NumToHex(
<nDecNumber> [, <nHexDigits> ]) β cHexNumber
converts a decimal number into a hexadecimal number. You can specify the length of the resulting hexadecimal number with<nHexDigits>. -
hb_Rand32() β nRandomInt
returns a random integer between0and0xFFFFFFFFinclusive. - (0xFFFFFFFF = 4.294.967.295) -
hb_Random(
[<x> [, <y>]]) β nRandomReal
returns a real number<n>so that:0 <= n < 1(if no params passed), or0 <= n < x(if only<x>passed), orx <= n < y(if<x>, <y>passed). Note: value of<y>(if any), is NOT included in values returned. -
hb_RandomInt(
[<x> [, <y>]]) β nRandomInt
returns an integer number<n>so that:1 <= n <= x(when onlyxpassed), orx <= n <= y(whenxandypassed), or0sand1salmost evenly distributed (when no params passed). Note: values ofx,y(if any), are INCLUDED in values returned. -
hb_RandomIntMax() β 2147483645
-
hb_RandomSeed(
<nSeed>) β NIL
seeds (i.e. initializes) the random number generator used byhb_Rand*family functions. It may be invoked once, before calling a 'randomizer' function. If the parameternSeedis0, then first call to hb_Random() or hb_RandomInt() activates initialization which generates new seed using current time in milliseconds and HVM stack address (for MT modes). If repeatable results needed from hb_Random() and hb_RandomInt() then the seed should be initialized for each thread with some fixed value i.e. hb_RandomSeed( 123456789 ) -
I2Bin(
<nInteger>) β cBinaryInteger
Converts a numeric value to a 16bit binary integer. returns a two-byte character string.
<nInteger>is an integer numeric value to be converted. Note: Decimal digits are truncated. -
Int(
<nExp>) β nInteger
returns the integer part of a numeric value, by truncating (but not rounding) all of its decimal digits (if any). The decimal part is lost. -
L2Bin(
<nExp>) β cBinaryInteger
returns a four-byte character string formatted as a 32-bit binary integer. -
LenNum(
<nNumber>) β nLength
returns the number of digits plus the decimal point, the decimal digits and the minus sign (if any) of a number, i.e. the number of characters needed to display/print the number. -
Log(
<nExp>) β nNaturalLog
returns the natural logarithm of a number. -
Max(
<xExp1>, <xExp2>) β xLarger
returns the larger numeric, date, datetime or logic value. On logic value larger is .T. -
Sqrt(
<nNumber>) β nSquareRoot
returns the square root of<nNumber>. The precision of this evaluation is based solely on the settings of the SET DECIMAL TO command. Any negative number passed as<nNumber>will always return a0. -
Str(
<nNumber>, [<nLength>], [<nDecimals>]) β cNumber
converts a numeric expression<nNumber>to a character string.
<nLength>is the length of the character string to return, including decimal digits, decimal point, and sign.<nDecimals>is the number of decimal places to return. -
StrZero(
<nNumber>, [<nLength>], [<nDecimals>]) β cNumber
converts a numeric expression<nNumber>to a character string, padded with leading zero(s).
<nNumber>is the numeric expression to be converted to a character string.<nLength>is the length of the character string to return, including decimal digits, decimal point, and sign.<nDecimals>is the number of decimal places to return.
* Copyright Β© 2016βpresent Pete D.