10 Trends Likely to Shape Enterprise Technology in 2024
The Ring programming language version 1.10 book - Part 127 of 212
1. Ring Documentation, Release 1.10
* :
* : <tuHighValue>
* : Specifies the higher value in the range.
* :
* Returns : <luReturnValue>
* : Returns a logical oder null value.
91.40 frSetSeparatorTo() function
* Syntax : frSetSeparatorTo(tuExpression)
* Description : Specifies the character for the numeric place separator.
* :
* Arguments : <tuExpression>
* : Specifies the character for the numeric place separator.
* :
* : Use frSetSeparatorTo() to change the numeric place
* : separator from de default, for example space " " or a comma ",".
* : Issue frSetSeparatorTo(Null) to reset the value to its default.
* :
* Returns : None
91.41 frTransform() function
* Syntax : tcReturnValue = frTransform(tuExpression, tcFormatCodes)
* Description : Returns a character string from an expression in a
* : format determined by a format code.
* Arguments : <tuExpression>
* : Specifies the expression to format.
* :
* : <tcFormatCodes>
* : Specifies one or more format codes that determine how to
* : format the expression.
* :
* Returns : <tcReturnValue>
The following table lists the available format codes for tcFormatCodes.
--------------------------------------------------------------------------
Format Code Description
--------------------------------------------------------------------------
@! Converts an entire character string to uppercase.
@T Trims leading and trailing spaces from character values.
@B Left-justifies Numeric data within the display region.
@L Pads numeric and string data with leading zeros.
@C Appends CR to positive numeric values to indicate a credit.
@X Appends DB to negative numeric values to indicate a debit.
--------------------------------------------------------------------------
91.42 frVarType() function
91.40. frSetSeparatorTo() function 1228
2. Ring Documentation, Release 1.10
* Syntax : lcRet = frVarType(tuExpression)
* Description : Returns the data type of an expression.
* :
* Arguments : <tuExpression>
* : Expecifies the expression for which the data type is returned.
* : frVartype() returns a
* : single character indicating the data type of the expression.
* : The following table lists the characteres that frVarType()
* : returns for each data type.
* :
* : ------------------- -------------------------------------
* : Return Value Data Type
* : ------------------- -------------------------------------
* : C Character
* : N Numeric
* : A List
* : O Object
* : U Undefined type
* : ------------------- -------------------------------------
* :
* Returns : Character
91.43 Example
Load "foxring.ring"
mf = new frFunctions
/*----------------------------------------------------------*/
* frProper() samples
/*----------------------------------------------------------*/
lcStr1 = "ring is a good language"
?mf.frProper(lcStr1)
?mf.frProper(Upper(lcStr1))
/*----------------------------------------------------------*/
* frStuff() samples
/*----------------------------------------------------------*/
lcStr1 = "abcdefghijklm"
lcStr2 = "12345"
// insert
?mf.frStuff(lcStr1, 4, 0, lcStr2)
// replace
?mf.frStuff(lcStr1, 4, 3, lcStr2)
// delete
?mf.frStuff(lcStr1, 4, 6, "")
// replace and insert
?mf.frStuff(lcStr1, 4, 1, lcStr2)
// replace and delete
?mf.frStuff(lcStr1, 4, 4, lcStr2)
// replace, delete rest
91.43. Example 1229
3. Ring Documentation, Release 1.10
?mf.frStuff(lcStr1, 4, Len(lcStr1), lcStr2)
/*----------------------------------------------------------*/
?mf.frAbs(-45)
?mf.frAbs(10-30)
?mf.frAbs(30-10)
lcNumber1 = 40
lcNumber2 = 2
?mf.frAbs(lcNumber2-lcNumber1)
lcCompletFileName = "C:ringdocssourcecontribute.txt"
?mf.frFile(lcCompletFileName, Null)
if mf.frFile(lcCompletFileName, Null) {
?mf.frFileToStr(lcCompletFileName)
else
?"File does not exist"
}
lcNewPath = "C:ring_2docssource"
?mf.frJustExt(lcCompletFileName)
?mf.frJustDrive(lcCompletFileName)
?mf.frJustStem(lcCompletFileName)
?mf.frForcePath(lcCompletFileName, lcNewPath)
?mf.frTransform(" Ring is a good language ",
"@! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
?mf.frAllTrim(" Ring is a good language ", Null)
?mf._version
lnValue = 3125.54
?mf.frTransform(lnValue, "@B")+ "Euros"
?mf.frTransform(lnValue, "@C 9999,999,999,999.999")
mf.frSetSeparatorTo(" ")
?mf.frTransform(lnValue, "9999,999,999,999.999")
?mf.frInt(lnValue)
?mf.frForceExt("teste", "dbf")
// Format "@L" Added into frTransform() function
?mf.frTransform("123", "@L 999999")
?mf.frTransform(123, "@L 999999")
91.43. Example 1230
4. CHAPTER
NINETYTWO
BIGNUMBER LIBRARY
In this chapter we will learn about using the Big Number library in the Ring programming language.
Developers : Bert Mariani, Gal Zsolt (~ CalmoSoft ~)
92.1 Loading the library
Before using the next function load the bignumber.ring library
load "bignumber.ring"
# Use Big Number library functions
92.2 Examples
Using the BigNumber library we can do arithmetic operations on huge numbers.
Example:
load "bignumber.ring"
num1 = "62345678901234567891678345123456789" ### Big
num2 = "1237894567890123419871236545" ### Small
num3 = "64" ### Divide Small
num4 = "765432"
num5 = "3" ### Power
? "Add big numbers:"
a1 = new BigNumber(num1) a1.Print()
a2 = new BigNumber(num2) a2.Print()
a3 = a1 + a2 a3.Print() ? nl
? "Substract big numbers:"
a1 = new BigNumber(num1) a1.Print()
a2 = new BigNumber(num2) a2.Print()
a3 = a1 - a2 a3.Print() ? nl
? "Multiply big numbers:"
a1 = new BigNumber(num1) a1.print()
a2 = new BigNumber(num2) a2.print()
a3 = a1 * a2 a3.print() ? nl
? "Divide big numbers:"
1231
5. Ring Documentation, Release 1.10
a1 = new BigNumber(num1) a1.print()
a2 = new BigNumber(num2) a2.print()
a3 = a1 / a2 a3.print() ? nl
? "Divide big numbers: by very small number"
a1 = new BigNumber(num1) a1.print()
a2 = new BigNumber(num3) a2.print()
a3 = a1 / a2 a3.print() ? nl
? "Power of big number:"
a1 = new BigNumber(num1) a1.print()
a2 = new BigNumber(num5) a2.print()
a3 = a1 ^ a2 a3.print() ? nl
Output:
Add big numbers:
62345678901234567891678345123456789
1237894567890123419871236545
62345680139129135781801764994693334
Substract big numbers:
62345678901234567891678345123456789
1237894567890123419871236545
52345687663340000001554925252220244
Multiply big numbers:
62345678901234567891678345123456789
1237894567890123419871236545
77177377243260150103462178714197454736432472780119682305154005
Divide big numbers:
62345678901234567891678345123456789
1237894567890123419871236545
50364288
Divide big numbers: by very small number
62345678901234567891678345123456789
64
974151232831790123307474142554012
Power of big number:
62345678901234567891678345123456789
3
242336636261471172092347146031727004 (Output continue in next line)
371698195628343934238988256152289508 (Output continue in next line)
493964611043228971692389860897069
92.3 BigNumber Functions
The library contains the next functions
92.3. BigNumber Functions 1232
6. Ring Documentation, Release 1.10
FuncAdd(num1,num2)
FuncSubtract(num1,num2)
FuncCompare(num1,num2)
FuncDivide(num1,num2)
FuncMultiply(num1,num2)
FuncPower(num1,num2)
FuncBinaryToDecimal(num1)
FuncDecimalToBinary(num1)
printBinaryDigits(binList)
printDecimalDigits(decList)
92.4 BigNumber Class
The library contains the next class
class BigNumber
func init aPara
func operator cOperator, Para
func print
func value
92.5 Library Source Code
You can see the library source code in : ring/ringlibs/bignumber folder
Source Code : https://github.com/ring-lang/ring/blob/master/ringlibs/bignumber/bignumber.ring
92.4. BigNumber Class 1233