home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / Val_README < prev    next >
Text File  |  1988-12-27  |  3KB  |  73 lines

  1.   VAL - An Expression Evaluator for your CLI C: directory
  2.                 Jim Butterfield .. December 12, 1988
  3.  
  4. EVAL doesn't do what I need.  VAL comes closer; it allows
  5. you to type in an expression (Basic- or C- style) and get
  6. the result in one shot.
  7.  
  8. YOU CAN type in a NUMBER .. hex or decimal .. and get it
  9. back in both number bases.  (No fractions).  Try...
  10.  
  11.      VAL 12     VAL -5    VAL $10    VAL 0x10    VAL -$228
  12.  
  13. Limits:  Numbers are 32-bit signed integers.  Well, signs
  14. are observed for multiply, divide, and modulo.  If you type
  15. too big a number, you'll be told.  No octal or binary
  16. numbers, please.
  17.  
  18. YOU CAN type a COUPLE OF NUMBERS separated by an operator.
  19. The operators are:
  20.  
  21.    ^        raise to a power
  22.    * / \ %  multiply, divide, modulo (either \ or %)
  23.    + -      addition, subtraction
  24.    &        bitwise AND
  25.    |        bitwise OR
  26.  
  27. Try...
  28.  
  29.    VAL 3+4     VAL 20*$30    VAL 2^10   VAL 100&$F
  30.    VAL 123*-2  VAL 345%10    VAL $400|3
  31.  
  32. Limits:  You may raise to a positive power only, since
  33. there are no fractions.  Overflow is checked, more or less,
  34. but what does overflow mean?  When you add $7FFFFFFF to 1,
  35. is that overflow or just a bigger hex number?  You'll be
  36. warned only about SERIOUS overflows, such as 2^99 or things
  37. like 123456*654321 or 123/0.  In most cases, you'll always
  38. use numbers that are within reasonable bounds.  Keep in mind
  39. that division produces an integer result.  I've never
  40. figured out how you truncate and do modulos on negative
  41. operations (-50/7 or 50%-7 or whatever) but I follow the
  42. most common C practices.  Try it out.
  43.  
  44. YOU CAN type WHOLE EXPRESSIONS.  These will use the normal
  45. Basic/C type hierarchies (as indicated in the order of the
  46. list above), but parentheses may be used to set up any
  47. evaluation order you like.  Try...
  48.  
  49.    VAL 2*-3+4*5    VAL 2*(3+4)*5    VAL (1-(2-(3-(4-5))))
  50.    VAL $C00276&$FFFF       VAL 0xC00276%2^16
  51.    VAL 2^3+2^10     VAL -7*-25|$10000      VAL -$228
  52.  
  53. As a technical note, I found that MUL and DIV instructions
  54. were not much help to me, since I felt that 16-bit values
  55. would crowd Amiga users.  To do an APTR to BPTR conversion,
  56. for example, you would want to do an operation such as
  57. $C00276/4.  That's too many active bits to suit the quick
  58. op codes; and when the need to handle signed numbers are
  59. taken into account, it's back to good old loop-and-test.
  60.  
  61. If you're interested in such things, I put this together
  62. using the Abacus/DataBecker ASSEMPRO package... I wanted to
  63. try that one out.  With resident assembler, editor, debugger
  64. and help (op code) modules, it's quick for small jobs like
  65. this.  Despite a few annoyances, it did this quite well.
  66. For bigger jobs, you'd want to do modules with some other
  67. assembler and then put 'em together with a linker.
  68.  
  69. It was fun to write.  Hope you find it useful.
  70.  
  71.                              Jim Butterfield, Toronto
  72.  
  73.