Eval module is one of my preferred modules. This module allows dynamic math functions being evaluated from text strings opening the road of many different options.
To start with this module here it is just little script using console for output:
[code=thinbasic]
USES "CONSOLE" '---We need Console module to write output
USES "EVAL" '---We need Eval module to evaluate math strings
DIM t0, t1 AS DOUBLE = TIMER '---Some timing variable
DIM MyFunction AS STRING '---Will contain math function to eval
'---Define Y = f(X) ... function
MyFunction = "y = COS(x) * 10 + SIN(x)"
'---Tells eval engine to define new 2 variables: x and y
Eval_SetNumber("x", 0)
Eval_SetNumber("y", 0)
'---Define a looper and its max
DIM Count AS LONG
DIM MaxCount AS LONG VALUE 50
FOR Count = -MaxCount to MaxCount
'---Set X value
Eval_SetNumber("x", Count)
'---Eval MyFunction
Eval(MyFunction)
'---Write some info output
CONSOLE_WRITELINE(format$(Count, "0000") & " " & Eval_GetNumber("y"))
NEXT
'---Measure the ending time
t1 = TIMER
'---Final results
CONSOLE_WRITELINE("------------------------------------------------------")
CONSOLE_WRITELINE("Time in seconds for " & str$(MaxCount * 2) & " loops: ")
CONSOLE_WRITELINE(FORMAT$(t1-t0, "#0.00000"))
CONSOLE_WRITELINE("------------------------------------------------------")
'---Wait for a key to stop execution
CONSOLE_WAITKEY
[/code]
More examples will come showing how to link script variable to Eval internal variables.
Also check about execution speed ...
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
That eval module is like petr's tbgl module, full of magic that makes wonderful things happen. My time was 0.047 seconds.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Bookmarks