SlideShare a Scribd company logo
Ring Documentation, Release 1.6
See "Cos(90) degree = " + cos(90*3.14/180) + nl
See "Tan(0) = " + tan(0) + nl
See "Tan(90) radians = " + tan(90) + nl
See "Tan(90) degree = " + tan(90*3.14/180) + nl
See "asin(0) = " + asin(0) + nl
See "acos(0) = " + acos(0) + nl
See "atan(0) = " + atan(0) + nl
See "atan2(1,1) = " + atan2(1,1) + nl
See "sinh(0) = " + sinh(0) + nl
See "sinh(1) = " + sinh(1) + nl
See "cosh(0) = " + cosh(0) + nl
See "cosh(1) = " + cosh(1) + nl
See "tanh(0) = " + tanh(0) + nl
See "tanh(1) = " + tanh(1) + nl
See "exp(0) = " + exp(0) + nl
See "exp(1) = " + exp(1) + nl
See "log(1) = " + log(1) + nl
See "log(2) = " + log(2) + nl
See "log10(1) = " + log10(1) + nl
See "log10(2) = " + log10(2) + nl
See "log10(10) = " + log10(10) + nl
See "Ceil(1.12) = " + Ceil(1.12) + nl
See "Ceil(1.72) = " + Ceil(1.72) + nl
See "Floor(1.12) = " + floor(1.12) + nl
See "Floor(1.72) = " + floor(1.72) + nl
See "fabs(1.12) = " + fabs(1.12) + nl
See "fabs(1.72) = " + fabs(1.72) + nl
See "pow(2,3) = " + pow(2,3) + nl
see "sqrt(16) = " + sqrt(16) + nl
Program Output:
Mathematical Functions
Sin(0) = 0
Sin(90) radians = 0.89
Sin(90) degree = 1.00
Cos(0) = 1
Cos(90) radians = -0.45
Cos(90) degree = 0.00
Tan(0) = 0
Tan(90) radians = -2.00
Tan(90) degree = 1255.77
asin(0) = 0
acos(0) = 1.57
atan(0) = 0
atan2(1,1) = 0.79
sinh(0) = 0
sinh(1) = 1.18
cosh(0) = 1
31.2. Example 233
Ring Documentation, Release 1.6
cosh(1) = 1.54
tanh(0) = 0
tanh(1) = 0.76
exp(0) = 1
exp(1) = 2.72
log(1) = 0
log(2) = 0.69
log10(1) = 0
log10(2) = 0.30
log10(10) = 1
Ceil(1.12) = 2
Ceil(1.72) = 2
Floor(1.12) = 1
Floor(1.72) = 1
fabs(1.12) = 1.12
fabs(1.72) = 1.72
pow(2,3) = 8
sqrt(16) = 4
31.3 Random() Function
The Random() function generate a random number and we can set the maximum value (optional).
Syntax:
Random(x) ---> Random number in the range [0,x]
Example:
for x = 1 to 20
see "Random number : " + random() + nl +
"Random number Max (100) : " + random(100) + nl
next
Program Output:
Random number : 31881
Random number Max (100) : 80
Random number : 5573
Random number Max (100) : 63
Random number : 2231
Random number Max (100) : 43
Random number : 12946
Random number Max (100) : 39
Random number : 22934
Random number Max (100) : 48
Random number : 4690
Random number Max (100) : 52
Random number : 13196
Random number Max (100) : 65
Random number : 30390
Random number Max (100) : 87
Random number : 4327
Random number Max (100) : 77
Random number : 12456
Random number Max (100) : 17
Random number : 28438
31.3. Random() Function 234
Ring Documentation, Release 1.6
Random number Max (100) : 13
Random number : 30503
Random number Max (100) : 6
Random number : 31769
Random number Max (100) : 94
Random number : 8274
Random number Max (100) : 65
Random number : 14390
Random number Max (100) : 90
Random number : 28866
Random number Max (100) : 12
Random number : 24558
Random number Max (100) : 70
Random number : 29981
Random number Max (100) : 77
Random number : 12847
Random number Max (100) : 63
Random number : 6632
Random number Max (100) : 60
31.4 Unsigned() Function
We can use unsigned numbers using the Unsigned() function.
Syntax:
Unsigned(nNum1,nNum2,cOperator) --> result of cOperator operation on nNum1,nNum2
Example:
see oat_hash("hello") + nl
# Jenkins hash function - https://en.wikipedia.org/wiki/Jenkins_hash_function
func oat_hash cKey
h = 0
for x in cKey
h = unsigned(h,ascii(x),"+")
h = unsigned(h,unsigned(h,10,"<<"),"+")
r = unsigned(h,6,">>")
h = unsigned(h, r,"^")
next
h = unsigned(h,unsigned(h,3,"<<"),"+")
h = unsigned(h,unsigned(h,11,">>"),"^")
h = unsigned(h,unsigned(h,15,"<<"),"+")
return h
Output:
3372029979.00
31.5 Decimals() Functions
We can determine the decimals numbers count after the point in float/double numbers using the decimals() function.
Syntax:
31.4. Unsigned() Function 235
Ring Documentation, Release 1.6
Decimals(nDecimalsCount)
Example:
x = 1.1234567890123
for d = 0 to 14
decimals(d)
see x + nl
next
Output:
1
1.1
1.12
1.123
1.1235
1.12346
1.123457
1.1234568
1.12345679
1.123456789
1.1234567890
1.12345678901
1.123456789012
1.1234567890123
1.12345678901230
31.6 Using _ in numbers
We can use _ between numbers digits.
Example:
x = 1_000_000
see type(x)+nl
see x+1+nl
Output:
NUMBER
100000001
31.7 Using f after numbers
We can use the ‘f’ letter after numbers.
Example:
x = 19.99f
see type(x) + nl
Output:
NUMBER
31.6. Using _ in numbers 236
CHAPTER
THIRTYTWO
FILES
In this chapter we are going to learn about files functions.
• Read()
• Write()
• Dir()
• Rename()
• Remove()
• fopen()
• fclose()
• fflush()
• freopen()
• tempfile()
• tempname()
• fseek()
• ftell()
• rewind()
• fgetpos()
• fsetpos()
• clearerr()
• feof()
• ferror()
• perror()
• fgetc()
• fgets()
• fputc()
• fputs()
• ungetc()
• fread()
237
Ring Documentation, Release 1.6
• fwrite()
• fexists()
• Numbers and Bytes
32.1 Read() Function
We can read the file content using the Read() function
Syntax:
Read(cFileName) ---> String contains the file content
Example:
see read("myfile.txt")
The read function can read binary files too
Example:
see read("myapp.exe")
32.2 Write() Function
We can write string to file using the Write() function
The write function can write binary data to binary files.
Syntax:
Write(cFileName,cString) # write string cString to file cFileName
Example:
# copy file
cFile = read("ring.exe")
write("ring2.exe",cFile)
32.3 Dir() Function
We can get the folder contents (files & sub folders) using the Dir() function.
Syntax:
Dir(cFolderPath) ---> List contains files & sub folders.
This function returns a list and each list item is a list of two items
• File/sub folder name
• Type (0 = File , 1 = Folder/Directory)
Example:
32.1. Read() Function 238
Ring Documentation, Release 1.6
see "Testing DIR() " + nl
mylist = dir("C:myfolder")
for x in mylist
if x[2]
see "Directory : " + x[1] + nl
else
see "File : " + x[1] + nl
ok
next
see "Files count : " + len(mylist)
32.4 Rename() Function
We can rename files using the Rename() function
Syntax:
Rename(cOldFileName,cNewFileName)
Example:
rename("file.txt","help.txt")
32.5 Remove() Function
We can delete a file using the Remove() function
Syntax:
Remove(cFileName)
Example:
remove("test.txt")
32.6 Fopen() Function
We can open a file using the Fopen() function
Syntax:
Fopen(cFileName,cMode) ---> File Handle
Mode Description
“r” Reading (The file must exist)
“w” Writing (create empty file / overwrite)
“a” Appends (create file if it doesn’t exist)
“r+” update (reading/writing)
“w+” Create empty file (reading/writing)
“a+” reading & appending
32.4. Rename() Function 239
Ring Documentation, Release 1.6
32.7 Fclose() Function
When we open a file using fopen() function, we can close it using the Fclose() function
Syntax:
Fclose(file handle)
32.8 Fflush() Function
We can flushes the output buffer of a stream using the Fflush() function
Syntax:
Fflush(file handle)
32.9 Freopen() Function
We can open another file using the same file handle and at the same time close the old file
Syntax:
Freopen(cFileName,cMode,file handle) ---> file handle
Example:
freopen("myprogoutput.txt","w+",stdout)
see "welcome" + nl
for x = 1 to 10
see x + nl
next
/*
** Read : https://en.wikipedia.org/wiki/Device_file#Device_files
** The next code is not portable, we can use iswindows() before
** using it and we can write special code for each operating system.
*/
freopen("CON","w",stdout) # For Microsoft Windows
see "Done" + nl # print to stdout again
Output:
# Output to stdout
Done
# Output to file : myprogoutput.txt
welcome
1
2
3
4
5
6
7
32.7. Fclose() Function 240
Ring Documentation, Release 1.6
8
9
10
32.10 Tempfile() Function
The function Tempfile() creates a temp. file (binary).
The file will be deleted automatically when the stream is closed
Syntax:
TempFile() ---> file handle
32.11 Tempname() Function
We can generate temp. file name using the Tempname() function
The generated name will be different from the name of any existing file
Syntax:
Tempname() ---> generated file name as string
32.12 Fseek() Function
We can set the file position of the stream using the Fseek() function
Syntax:
Fseek(file handle, nOffset, nWhence) ---> zero if successful
The next table presents the nWhence values
Value Description
0 Beginning of file
1 Current position
2 End of file
32.13 Ftell() Function
We can know the current file position of a stream using the Ftell() function
Syntax:
Ftell(file handle) ---> file position as number
32.10. Tempfile() Function 241
Ring Documentation, Release 1.6
32.14 Rewind() Function
We can set the file position to the beginning of the file using the Rewind() function
Syntax:
Rewind(file handle)
32.15 Fgetpos() Function
We can get handle to the current file position using the Fgetpos() function
Syntax:
Fgetpos(file handle) ---> position handle
32.16 Fsetpos() Function
We can set the current file position using the Fgetpos() function
Syntax:
Fsetpos(file handle,position handle)
32.17 Clearerr() Function
We can clear the EOF error and the error indicators of a stream using the clearerr() function
Syntax:
Clearerr(file handle)
32.18 Feof() Function
We can test the end-of-file indicator using the Feof() function
Syntax:
Feof(file handle) ---> returns 1 if EOF and 0 if not
32.19 Ferror() Function
We can test the error indicator of a given stream using the Ferror() function
Syntax:
Ferror(file handle) ---> returns 1 if error and 0 if not
32.14. Rewind() Function 242

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.4 book - Part 18 of 30
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 36 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 25 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 24 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 45 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 42 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 34 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 23 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 35 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 34 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 36 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 45 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4.1 book - Part 7 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 44 of 210
Mahmoud Samir Fayed
 
PDF
はじめてのGroovy
Tsuyoshi Yamamoto
 
PDF
The Ring programming language version 1.10 book - Part 33 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 43 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4.1 book - Part 13 of 31
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.4 book - Part 10 of 30
Mahmoud Samir Fayed
 
PDF
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
 
The Ring programming language version 1.4 book - Part 18 of 30
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 36 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 25 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 24 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 45 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 42 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 34 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 23 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 35 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 34 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 36 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 45 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 7 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 44 of 210
Mahmoud Samir Fayed
 
はじめてのGroovy
Tsuyoshi Yamamoto
 
The Ring programming language version 1.10 book - Part 33 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 43 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.4.1 book - Part 13 of 31
Mahmoud Samir Fayed
 
The Ring programming language version 1.4 book - Part 10 of 30
Mahmoud Samir Fayed
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Tsuyoshi Yamamoto
 

Similar to The Ring programming language version 1.6 book - Part 27 of 189 (19)

PDF
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 14 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 26 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 28 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 40 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.1 book - Part 24 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.3 book - Part 27 of 88
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 26 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.9 book - Part 33 of 210
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 29 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 26 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.2 book - Part 36 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 34 of 185
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 24 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.8 book - Part 29 of 202
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 16 of 84
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 14 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 26 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 28 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 40 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.1 book - Part 24 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 27 of 88
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 26 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.9 book - Part 33 of 210
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 29 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 26 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.7 book - Part 30 of 196
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 36 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 35 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 34 of 185
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 24 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 29 of 202
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 16 of 84
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 43 of 212
Mahmoud Samir Fayed
 
Ad

More from Mahmoud Samir Fayed (20)

PDF
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 212 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 211 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 210 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 208 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 207 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 205 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 206 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 204 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 203 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 202 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 201 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 200 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 199 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 198 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 197 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 196 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 195 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 194 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 193 of 212
Mahmoud Samir Fayed
 
The Ring programming language version 1.10 book - Part 192 of 212
Mahmoud Samir Fayed
 
Ad

Recently uploaded (20)

PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Customise Your Correlation Table in IBM SPSS Statistics.pptx
Version 1 Analytics
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
MiniTool Power Data Recovery 8.8 With Crack New Latest 2025
bashirkhan333g
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Tally software_Introduction_Presentation
AditiBansal54083
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 

The Ring programming language version 1.6 book - Part 27 of 189

  • 1. Ring Documentation, Release 1.6 See "Cos(90) degree = " + cos(90*3.14/180) + nl See "Tan(0) = " + tan(0) + nl See "Tan(90) radians = " + tan(90) + nl See "Tan(90) degree = " + tan(90*3.14/180) + nl See "asin(0) = " + asin(0) + nl See "acos(0) = " + acos(0) + nl See "atan(0) = " + atan(0) + nl See "atan2(1,1) = " + atan2(1,1) + nl See "sinh(0) = " + sinh(0) + nl See "sinh(1) = " + sinh(1) + nl See "cosh(0) = " + cosh(0) + nl See "cosh(1) = " + cosh(1) + nl See "tanh(0) = " + tanh(0) + nl See "tanh(1) = " + tanh(1) + nl See "exp(0) = " + exp(0) + nl See "exp(1) = " + exp(1) + nl See "log(1) = " + log(1) + nl See "log(2) = " + log(2) + nl See "log10(1) = " + log10(1) + nl See "log10(2) = " + log10(2) + nl See "log10(10) = " + log10(10) + nl See "Ceil(1.12) = " + Ceil(1.12) + nl See "Ceil(1.72) = " + Ceil(1.72) + nl See "Floor(1.12) = " + floor(1.12) + nl See "Floor(1.72) = " + floor(1.72) + nl See "fabs(1.12) = " + fabs(1.12) + nl See "fabs(1.72) = " + fabs(1.72) + nl See "pow(2,3) = " + pow(2,3) + nl see "sqrt(16) = " + sqrt(16) + nl Program Output: Mathematical Functions Sin(0) = 0 Sin(90) radians = 0.89 Sin(90) degree = 1.00 Cos(0) = 1 Cos(90) radians = -0.45 Cos(90) degree = 0.00 Tan(0) = 0 Tan(90) radians = -2.00 Tan(90) degree = 1255.77 asin(0) = 0 acos(0) = 1.57 atan(0) = 0 atan2(1,1) = 0.79 sinh(0) = 0 sinh(1) = 1.18 cosh(0) = 1 31.2. Example 233
  • 2. Ring Documentation, Release 1.6 cosh(1) = 1.54 tanh(0) = 0 tanh(1) = 0.76 exp(0) = 1 exp(1) = 2.72 log(1) = 0 log(2) = 0.69 log10(1) = 0 log10(2) = 0.30 log10(10) = 1 Ceil(1.12) = 2 Ceil(1.72) = 2 Floor(1.12) = 1 Floor(1.72) = 1 fabs(1.12) = 1.12 fabs(1.72) = 1.72 pow(2,3) = 8 sqrt(16) = 4 31.3 Random() Function The Random() function generate a random number and we can set the maximum value (optional). Syntax: Random(x) ---> Random number in the range [0,x] Example: for x = 1 to 20 see "Random number : " + random() + nl + "Random number Max (100) : " + random(100) + nl next Program Output: Random number : 31881 Random number Max (100) : 80 Random number : 5573 Random number Max (100) : 63 Random number : 2231 Random number Max (100) : 43 Random number : 12946 Random number Max (100) : 39 Random number : 22934 Random number Max (100) : 48 Random number : 4690 Random number Max (100) : 52 Random number : 13196 Random number Max (100) : 65 Random number : 30390 Random number Max (100) : 87 Random number : 4327 Random number Max (100) : 77 Random number : 12456 Random number Max (100) : 17 Random number : 28438 31.3. Random() Function 234
  • 3. Ring Documentation, Release 1.6 Random number Max (100) : 13 Random number : 30503 Random number Max (100) : 6 Random number : 31769 Random number Max (100) : 94 Random number : 8274 Random number Max (100) : 65 Random number : 14390 Random number Max (100) : 90 Random number : 28866 Random number Max (100) : 12 Random number : 24558 Random number Max (100) : 70 Random number : 29981 Random number Max (100) : 77 Random number : 12847 Random number Max (100) : 63 Random number : 6632 Random number Max (100) : 60 31.4 Unsigned() Function We can use unsigned numbers using the Unsigned() function. Syntax: Unsigned(nNum1,nNum2,cOperator) --> result of cOperator operation on nNum1,nNum2 Example: see oat_hash("hello") + nl # Jenkins hash function - https://en.wikipedia.org/wiki/Jenkins_hash_function func oat_hash cKey h = 0 for x in cKey h = unsigned(h,ascii(x),"+") h = unsigned(h,unsigned(h,10,"<<"),"+") r = unsigned(h,6,">>") h = unsigned(h, r,"^") next h = unsigned(h,unsigned(h,3,"<<"),"+") h = unsigned(h,unsigned(h,11,">>"),"^") h = unsigned(h,unsigned(h,15,"<<"),"+") return h Output: 3372029979.00 31.5 Decimals() Functions We can determine the decimals numbers count after the point in float/double numbers using the decimals() function. Syntax: 31.4. Unsigned() Function 235
  • 4. Ring Documentation, Release 1.6 Decimals(nDecimalsCount) Example: x = 1.1234567890123 for d = 0 to 14 decimals(d) see x + nl next Output: 1 1.1 1.12 1.123 1.1235 1.12346 1.123457 1.1234568 1.12345679 1.123456789 1.1234567890 1.12345678901 1.123456789012 1.1234567890123 1.12345678901230 31.6 Using _ in numbers We can use _ between numbers digits. Example: x = 1_000_000 see type(x)+nl see x+1+nl Output: NUMBER 100000001 31.7 Using f after numbers We can use the ‘f’ letter after numbers. Example: x = 19.99f see type(x) + nl Output: NUMBER 31.6. Using _ in numbers 236
  • 5. CHAPTER THIRTYTWO FILES In this chapter we are going to learn about files functions. • Read() • Write() • Dir() • Rename() • Remove() • fopen() • fclose() • fflush() • freopen() • tempfile() • tempname() • fseek() • ftell() • rewind() • fgetpos() • fsetpos() • clearerr() • feof() • ferror() • perror() • fgetc() • fgets() • fputc() • fputs() • ungetc() • fread() 237
  • 6. Ring Documentation, Release 1.6 • fwrite() • fexists() • Numbers and Bytes 32.1 Read() Function We can read the file content using the Read() function Syntax: Read(cFileName) ---> String contains the file content Example: see read("myfile.txt") The read function can read binary files too Example: see read("myapp.exe") 32.2 Write() Function We can write string to file using the Write() function The write function can write binary data to binary files. Syntax: Write(cFileName,cString) # write string cString to file cFileName Example: # copy file cFile = read("ring.exe") write("ring2.exe",cFile) 32.3 Dir() Function We can get the folder contents (files & sub folders) using the Dir() function. Syntax: Dir(cFolderPath) ---> List contains files & sub folders. This function returns a list and each list item is a list of two items • File/sub folder name • Type (0 = File , 1 = Folder/Directory) Example: 32.1. Read() Function 238
  • 7. Ring Documentation, Release 1.6 see "Testing DIR() " + nl mylist = dir("C:myfolder") for x in mylist if x[2] see "Directory : " + x[1] + nl else see "File : " + x[1] + nl ok next see "Files count : " + len(mylist) 32.4 Rename() Function We can rename files using the Rename() function Syntax: Rename(cOldFileName,cNewFileName) Example: rename("file.txt","help.txt") 32.5 Remove() Function We can delete a file using the Remove() function Syntax: Remove(cFileName) Example: remove("test.txt") 32.6 Fopen() Function We can open a file using the Fopen() function Syntax: Fopen(cFileName,cMode) ---> File Handle Mode Description “r” Reading (The file must exist) “w” Writing (create empty file / overwrite) “a” Appends (create file if it doesn’t exist) “r+” update (reading/writing) “w+” Create empty file (reading/writing) “a+” reading & appending 32.4. Rename() Function 239
  • 8. Ring Documentation, Release 1.6 32.7 Fclose() Function When we open a file using fopen() function, we can close it using the Fclose() function Syntax: Fclose(file handle) 32.8 Fflush() Function We can flushes the output buffer of a stream using the Fflush() function Syntax: Fflush(file handle) 32.9 Freopen() Function We can open another file using the same file handle and at the same time close the old file Syntax: Freopen(cFileName,cMode,file handle) ---> file handle Example: freopen("myprogoutput.txt","w+",stdout) see "welcome" + nl for x = 1 to 10 see x + nl next /* ** Read : https://en.wikipedia.org/wiki/Device_file#Device_files ** The next code is not portable, we can use iswindows() before ** using it and we can write special code for each operating system. */ freopen("CON","w",stdout) # For Microsoft Windows see "Done" + nl # print to stdout again Output: # Output to stdout Done # Output to file : myprogoutput.txt welcome 1 2 3 4 5 6 7 32.7. Fclose() Function 240
  • 9. Ring Documentation, Release 1.6 8 9 10 32.10 Tempfile() Function The function Tempfile() creates a temp. file (binary). The file will be deleted automatically when the stream is closed Syntax: TempFile() ---> file handle 32.11 Tempname() Function We can generate temp. file name using the Tempname() function The generated name will be different from the name of any existing file Syntax: Tempname() ---> generated file name as string 32.12 Fseek() Function We can set the file position of the stream using the Fseek() function Syntax: Fseek(file handle, nOffset, nWhence) ---> zero if successful The next table presents the nWhence values Value Description 0 Beginning of file 1 Current position 2 End of file 32.13 Ftell() Function We can know the current file position of a stream using the Ftell() function Syntax: Ftell(file handle) ---> file position as number 32.10. Tempfile() Function 241
  • 10. Ring Documentation, Release 1.6 32.14 Rewind() Function We can set the file position to the beginning of the file using the Rewind() function Syntax: Rewind(file handle) 32.15 Fgetpos() Function We can get handle to the current file position using the Fgetpos() function Syntax: Fgetpos(file handle) ---> position handle 32.16 Fsetpos() Function We can set the current file position using the Fgetpos() function Syntax: Fsetpos(file handle,position handle) 32.17 Clearerr() Function We can clear the EOF error and the error indicators of a stream using the clearerr() function Syntax: Clearerr(file handle) 32.18 Feof() Function We can test the end-of-file indicator using the Feof() function Syntax: Feof(file handle) ---> returns 1 if EOF and 0 if not 32.19 Ferror() Function We can test the error indicator of a given stream using the Ferror() function Syntax: Ferror(file handle) ---> returns 1 if error and 0 if not 32.14. Rewind() Function 242