home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
199.lha
/
Val_README
< prev
next >
Wrap
Text File
|
1988-12-27
|
3KB
|
73 lines
VAL - An Expression Evaluator for your CLI C: directory
Jim Butterfield .. December 12, 1988
EVAL doesn't do what I need. VAL comes closer; it allows
you to type in an expression (Basic- or C- style) and get
the result in one shot.
YOU CAN type in a NUMBER .. hex or decimal .. and get it
back in both number bases. (No fractions). Try...
VAL 12 VAL -5 VAL $10 VAL 0x10 VAL -$228
Limits: Numbers are 32-bit signed integers. Well, signs
are observed for multiply, divide, and modulo. If you type
too big a number, you'll be told. No octal or binary
numbers, please.
YOU CAN type a COUPLE OF NUMBERS separated by an operator.
The operators are:
^ raise to a power
* / \ % multiply, divide, modulo (either \ or %)
+ - addition, subtraction
& bitwise AND
| bitwise OR
Try...
VAL 3+4 VAL 20*$30 VAL 2^10 VAL 100&$F
VAL 123*-2 VAL 345%10 VAL $400|3
Limits: You may raise to a positive power only, since
there are no fractions. Overflow is checked, more or less,
but what does overflow mean? When you add $7FFFFFFF to 1,
is that overflow or just a bigger hex number? You'll be
warned only about SERIOUS overflows, such as 2^99 or things
like 123456*654321 or 123/0. In most cases, you'll always
use numbers that are within reasonable bounds. Keep in mind
that division produces an integer result. I've never
figured out how you truncate and do modulos on negative
operations (-50/7 or 50%-7 or whatever) but I follow the
most common C practices. Try it out.
YOU CAN type WHOLE EXPRESSIONS. These will use the normal
Basic/C type hierarchies (as indicated in the order of the
list above), but parentheses may be used to set up any
evaluation order you like. Try...
VAL 2*-3+4*5 VAL 2*(3+4)*5 VAL (1-(2-(3-(4-5))))
VAL $C00276&$FFFF VAL 0xC00276%2^16
VAL 2^3+2^10 VAL -7*-25|$10000 VAL -$228
As a technical note, I found that MUL and DIV instructions
were not much help to me, since I felt that 16-bit values
would crowd Amiga users. To do an APTR to BPTR conversion,
for example, you would want to do an operation such as
$C00276/4. That's too many active bits to suit the quick
op codes; and when the need to handle signed numbers are
taken into account, it's back to good old loop-and-test.
If you're interested in such things, I put this together
using the Abacus/DataBecker ASSEMPRO package... I wanted to
try that one out. With resident assembler, editor, debugger
and help (op code) modules, it's quick for small jobs like
this. Despite a few annoyances, it did this quite well.
For bigger jobs, you'd want to do modules with some other
assembler and then put 'em together with a linker.
It was fun to write. Hope you find it useful.
Jim Butterfield, Toronto