Go to Triangle Digital Support Home Page TDS2020F TECHNICAL MANUAL
Programming
Mathematical operations
Live website search
Enter key words
 

MATHEMATICAL OPERATIONS

DEFINITIONS

Only integer mathematics in the Forth ROM are shown, see below for a summary of integer extensions, floating point and other methods.

 

*

( n1 n2 - n1*n2 )

 

*/

( n1 n2 n3 - n4 )

Scale n1 by ratio n2/n3.

*/MOD

( n1 n2 n3 - n4 n5 )

Leave quotient n5 and remainder n4 of operation n1*n2/n3.

+

( n1 n2 - n1+n2 )

 

+!

( n addr - )

Add n to value at address.

-

( n1 n2 - n1-n2 )

 

/

( n1 n2 - n1/n2 )

 

/MOD

( n1 n2 - rem quot )

Leave remainder and signed quotient n1/n2.

0<

( n - f )

True if number less than zero.

0<>

( n - f )

f = -1 if n not zero, f = 0 if n is zero.

0=

( n - f )

True if number equal to zero.

0>

( n - f )

True if number greater than zero.

1+

( n - n+1 )

 

1-

( n - n-1 )

 

2*

( n - n*2 )

 

2+

( n - n+2 )

 

2-

( n - n-2 )

 

2/

( n - n/2 )

 

<

( n1 n2 - f )

True if n1 less than n2.

<>

( n1 n2 - f )

True if n1 not equal to n2.

=

( n1 n2 - f )

True if n1 equal to n2.

>

( n1 n2 - f )

True if n1 greater than n2.

ABS

( n - u )

Leave absolute value u of number n.

D*S

( d1 n - d2 )

d2=d1*n

D+

( d1 d2 - d1+d2 )

 

D-

( d1 d2 - d1-d2 )

 

D/

( d1 d2 - n )

n=d1/d2

D/S

( d1 n - d2 )

d2=d1/n

D0<

( d - f )

True if double number less than 0.

D0=

( d - f )

True if double number equal to zero.

D2*

( d - d*2 )

 

D2/

( d - d/2 )

 

D<

( d1 d2 - f )

True if d1 less than d2.

D=

( d1 d2 - f )

True if d1 equal to d2.

D>S

( d - n )

Convert double number to single.

DABS

( d - ud )

Leave absolute value ud of double number d.

DMAX

( d1 d2 - d3)

d3 is the greater of d1 and d2

DMIN

( d1 d2 -- d3)

d3 is the lesser  of d1 and d2

DNEGATE

( d1 - d2 )

d2=-d1

DU<

( ud1 ud2 - f )

True if ud1 less than ud2.

M*

( n1 n2 - d )

d=n1*n2

M*/

( d1 n1 n2 - d2 )

Scale double number d1 by ratio n1/n2.

M+

( d1 n - d2 )

d2=d1+n

MAX

( n1 n2 - n3 )

n3 is the greater of n1 and n2.

MIN

( n1 n2 - n3 )

n3 is the lesser of n1 and n2.

MOD

( n1 n2 - n3 )

n3 is the remainder of n1/n2.

NEGATE

( n1 - n2 )

n2= -n1

S>D

( n - d )

Sign extend single number n to form double number d.

T*

( ud u - ut )

ud * u giving 48-bit product.

T/

( ut u - ud )

ut / u 48-bit integer divided by single to give double integer.

U<

( u1 u2 - f )

True if u1 less than u2.

U>

( u1 u2 - f )

True if u1 greater than u2.

UM*

( u1 u2 - ud )

ud=u1*u2

UM/MOD

( ud u1 - u2 u3 )

Leave remainder u2 and quotient u3 of ud/u1.

INTEGER TYPES (Forth ROM, #MATH.TDS & #MATH1.TDS)

Use integer (16-bit) or double-integer (32-bit) where possible because you get the best speed. Both are built into the Forth kernel of the TDS2020F. Scaling the input and output to fit in the range �2,000,000,000 generally allows this.

Integer functions in the Forth ROM are shown above but in the files #MATH.TDS & #MATH1.TDS there are many others including 48-bit and 64-bit arithmetic, logarithms, exponentials and trigonometry.

FIXED POINT (#FIXED.TDS-comes with Update Service)

Uses 32-bit integer arithmetic for speed and accuracy but has fixed decimal point for input and output. You can choose between 0 and 4 decimal places.

FRACTIONAL ARITHMETIC (#TRIG.TDS-comes with Update Service)

This uses 16-bit integer arithmetic for speed. You scale input and output to the range �2.000 before using the mathematical operations. Apart from the main four functions and conversion words, sine, cosine, logarithms, exponentials, inverse sine & cosine and square roots are provided.

FLOATING POINT (TDS-FLOAT-ANS-optional extra)
Click here for full details of the ANS Floating Point software, the following is only a summary.

DESCRIPTION

The package TDS-FLOAT-ANS is a fully featured floating-point package for the TDS2020F available as an option. Use the parts of it you need in your application code.

Be sure you really need floating point. Floating point arithmetic enables very small numbers (like 0.0000000001) to very large numbers (like 3000000000000) to be handled at the same time. This is very rarely needed and the extensive 32-bit double number arithmetic routines in the TDS2020F cater for most needs. These can handle from 0 to �2000000000, or 0.00000 to �20000.00000 for example.

Occasions do arise where floating point would be useful-please request a copy of the 16-page TDS-FLOAT-ANS Technical Manual. The software is supplied as source code on disk. Apart from normal calculator functions, a full range of trigonometrical and log/exponential functions is included with accuracy 8 to 10 decimal digits.

TYPICAL PERFORMANCE

These are measured using TDS2020F. Adding the TDS2020DV development board will make times longer.

 

Floating point multiply F*

0.6ms

Floating point divide F/

5.4ms

Floating point add F+

0.49ms

Floating point subtract F-

0.45ms

Floating point sine FSIN

13.7ms

Floating point logarithm FLOG

12.3ms

 

STACK & ADDRESS MANIPULATION

   F!      F@     FALIGN FALIGNED   FCONSTANT  FDEPTH

   FDROP   FDUP   FINT FLITERAL   FLOAT+     FLOATS

   FOVER   FROT FSWAP    FVARIABLE

ARITHMETIC

   F*      F+     F- F/     F0<    F0= F2*

   F2/     F      FLOOR  FMAX   FMIN FNEGATE FROUND

   FSQRT   F~

TRIGONOMETRY

   DEG>RAD FACOS FASIN  FATAN  FATAN2 FCOS    FSIN

   FSINCOS FTAN   PI     PI/2   PI/4 RAD>DEG

HYPERBOLIC FUNCTIONS

   FACOSH  FASINH FATANH FCOSH  FSINH FTANH

EXPONENTIALS & POWERS

   FALOG   FEXP FEXPM1 F**

LOGARITHM

   SFLN    FLNP1 FLOG

INPUT FUNCTIONS

   >FLOAT   D>F FINPUT"  FLOAT-OFF  FLOAT-ON S>F

OUTPUT FUNCTIONS

   F>S   F.    F>D FE.    FS.   PRECISION REPRESENT

   SET-PRECISION

IEEE FLOATING POINT REPRESENTATION

   DF!   DF@   DFALIGN DFALIGNED  DFLOAT+  DFLOATS

   SF!   SF@ SFALIGN  SFALIGNED  SFLOAT+ SFLOATS

FOURIER TRANSFORMS (TDS2020FFT-optional extra)

A demonstration Fast Fourier Transform program is provided with the Starter Pack. A separate data sheet gives details of the full version.

Go to Triangle Digital Support Home Page Go to top   Next page