-
Notifications
You must be signed in to change notification settings - Fork 4
Numbers handling
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 ofe
raised to the specified power. The maximum value of<nExponent>
is46
otherwise 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 leastnDecs
significant 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 ornull
string, 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 between0
and0xFFFFFFFF
inclusive. - (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 onlyx
passed), orx <= n <= y
(whenx
andy
passed), or0s
and1s
almost 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 parameternSeed
is0
, 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.
Harbour Functions Dictionary Many of the entries presented in this wiki, have been obtained from various sources (see References); however, a good number of them have been written «from scratch» (or rewritten/corrected), particularly those referring to newer Harbour functions. Anyway, it's a 'work in progress', so there might be omissions, oversights and / or errors. That said, any suggestion/correction/comment are more than welcome --many thanks, to those few who already have made contributions!
Harbour exclusive functions | Clipper compatible functions |
---|---|
hb_A | A |
hb_B | B |
hb_C | C |
hb_D | D |
hb_E | E |
hb_F | F |
hb_G | G |
hb_H | H |
hb_I | I |
hb_J_K | J K |
hb_L | L |
hb_M | M |
hb_N_O | N O |
hb_P | P |
hb_R | Q R |
hb_S | S |
hb_T | T |
hb_U | U |
hb_V | V W |
hb_W | X Y |
- Contrib. Libraries
HBWIN WinAPI Library | Compress Libraries |
HBHPDF Library (Haru) | Multi Threading |
Harbour Socket API | hbCT (Cl*pper tools) |
Serial API | hbNF (NanForum library) |
HBCURL cURL API Library | Mini-XML docs |
-
praeterea lectio...
Miscellaneous Readings