Jan 18, 2003
RE: Math using floating point numbers within Vedit
I also wanted to give Vedit floating point math. So I tried different
methods to learn which method is the easiest or fastest for Vedit.
Please note, all of my solutions place a ASCII string in a Vedit
text register. The string is an equation made of a floating point number
(ie +.00113 or -355000.) and a math operator and a second
floating point number. Then it passes the string to some type of a
program to solve the a math equation. Lastly return the result to a
location where Vedit can find it and put it back into a text register.
The Vedit Plus for MSDOS has some commands not found in
Vedit Plus for Windows. These commands allow user binary code to be
included with Vedit Plus and executed. The user writes an assembly
level subroutine. This assembly code includes reserved memory location
to pass an argument and return the result. Vedit Plus for MSDOS must do
Sys_Malloc(n) allocate a number of memory bytes
Sys_Block_Write(r,mem) copy user subroutine to above
Sys_Reg_Address(r) point to input argument location
Sys_Call(mem) execute user subroutine
Sys_Block_Read(r,mem1,mem2) return results back to Vedit Plus
My user subroutine for floating point equation uses the Intel
Binary Coded Decimal series of math instructions. The benchmark
for this method is .55 msec per equation.
I wrote a second user subroutine that uses the Intel floating point
coprocessor. The benchmark for this method is .42 msec per equation.
It is the fastest solution, but is not easy to use. A copy of this
is in a file called FPMATH09.ZIP
Another easy solution is to run an existing 3rd party program that does
floating point math. An example of a 3rd party is a MSDOS port of UNIX AWK.
Vedit Plus for MSDOS or Vedit Plus for Windows must
Write the string or equation to a RAMDISK file
Shell out and execute a 3rd party program or
Run AWK from Vedit with System("D:AWK -f D:MYTEST.AWK D:EQUATION.TXT",NOMSG=
)
The 3rd party program will read the equation, solve it,
write result to disk, and quit
Vedit Plus then reads the result from RAMDISK
by Reg_Load(r,"D:RESULT.TXT")
The benchmark for this method is 200 msec per equation.
Here is a sample of the simple MATH_AWK method
The AWK needed may be found at http://www.simtel.net/pub/pd/51371.html
run vedit -x MATH_AWK.VDM and then view the file RESULT.TXT
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
// FIRST LINE OF FILENAME MATH_AWK.VDM
//
Reg_Set(53,"355.")=09=09// set Y variable ready for arithmetic
Reg_Set(54,".113")=09=09// set X variable ready for arithmetic
Reg_Set(55," / ")=09=09// set math operator !!! WITH spaces !!!
=09=09=09=09// spaces are delimiters in AWK
Reg_Set(59,@53)=09=09=09// build equation with first variable
Reg_Set(59,@55,APPEND)=09=09// build equation with math operator
Reg_Set(59,@54,APPEND)=09=09// build equation with second variable
Reg_Save(59,"D:EQUATION.TXT",OK)=09// save source data to disk
//
System("D:AWK -f D:MYTEST.AWK D:EQUATION.TXT",NOMSG)=09// do math with AWK
//
Reg_Load(61,"D:RESULT.TXT")=09=09// get answer back to Vedit
QALLY=09=09=09=09=09// quit vedit
// LAST LINE OF FILENAME MATH_AWK.VDM
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
# First Line of Filename MYTEST.AWK
{
if ($2 =3D=3D "+") answer =3D $1 + $3
if ($2 =3D=3D "-") answer =3D $1 - $3
if ($2 =3D=3D "*") answer =3D $1 * $3
if ($2 =3D=3D "/") answer =3D $1 / $3
if ($1 =3D=3D "=FB") answer =3D sqrt($2)
if ($1 =3D=3D "sin") answer =3D sin($2*3.1459/180)
print (answer) > "D:result.txt"
}
# Last Line of Filename MYTEST.AWK
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
In the Vedit E-mail Newsletter Oct 23, 2001, Mr. Green writes that
Mr Tom Burt will try to write a Sendkey() function into Vedit. With
Sendkey() Vedit could;
write the floating point equation to the Windows clipboard
Sendkey() paste from clipboard to Windows program CALC.EXE
Sendkey() =3D or solve equation and return result
Sendkey() copy to clipboard
read the result back into Vedit from the clipboard
The benchmark for this method is unknown.
Mr Ziemski provided us with FLOATMATH.VDM. His method is to rescale the
floating point number into the smallest integer (the scale will be
variable to make the smallest number). Then pass the integer
equation to Vedit Plus for a solution. Then restore the result
integer back to a floating point from reusing the variable scale.
The benchmark for his method is 2.2 msec per equation.
A note to Mr. Ziemski,
Your macro FLOATMATH.VDM is good work.
Also about error handling to Mr. Ziemski.
My floating point subroutine also does NOT have error handling checking.
I found if it written to use a number 100 times the range of the numbers
that really sees, then I did not find errors. I use fixed scaling
(by 1,000,000,000,000,000,000) for 128 bit inputs then only keep 64 bits.
This should allow error checking to be easier. I did not try to write a
Vedit macro like yours because I estimated it would be too slow.
But you proved that 2.2 msec solution is not slow, it is good solution.
Thank you
A note to Mr. Green,
32 bit signed integer of Vedit Plus
MAX RESULT SQUARE ROOT of MAX RESULT SAFE ASCII INPUT RANG=
E
2,147,483,647 46,340 10,000 to .0001
64 bit signed integer of Vedit Pro64
MAX RESULT SQUARE ROOT of MAX RESULT SAFE ASCII INPUT RANG=
E
9,223,372,036,854,775,807 3,037,000,499 1,000,000,000 to .00000000=
1
32 bit signed integers make the safe ASCII input range too narrow for my
needs. However 64 bit signed integers found in old Intel coprocessors
and your future Vedit Pro64 meet my range requirements. I plan to write
a Vedit macro with fixed scaling (always by 1,000,000,000) of the ASCII
numeric string when Vedit Pro64 is released. I can benchmark Greenview
Data's use of 64 bit instructions against my use of the coprocessor
64 bit instructions (.42 msec per equation). I believe that myself and
other Vedit users like the quick action seen from assembly code.
Thank you
--=20
kenjen@... Ken Jensen Portland, Oregon USA
---------------------------------------------------------
|
|