Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Conklin E.K.Forth programmer's handbook.2000.pdf
Скачиваний:
321
Добавлен:
23.08.2013
Размер:
2.04 Mб
Скачать

 

 

Forth Programmer’s Handbook

played is set by SET-PRECISION. “F-S-dot”

 

PRECISION

( — u )

Floating Ext

Return the number of significant digits currently displayed by F., FE., or FS..

SET-PRECISION

( u — )

Floating Ext

Set the number of significant digits to be used by F., FE., or FS. to u.

3.8.4 Floating-Point Constants, Variables, and Literals

There are floating-point counterparts to the integer Forth words CONSTANT, VARIABLE, and LITERAL. The memory storage requirements, maximum value, and precision of the floating-point versions are implementation specific.

Glossary

 

 

FCONSTANT <name>

( F: r — )

Floating

Define a floating-point constant with the given name whose value is r, e.g., 3.14159E FCONSTANT PI. When name is executed, the value r is returned on the floating-point stack. “F-constant”

FLITERAL ( F: r — ) Floating

Used only within a definition. When the definition is compiled and the word FLITERAL is reached, there must be a value r on the floating-point stack, which will be removed and added to the definition. When the definition is executed, FLITERAL returns the value r on the floating-point stack. “F-literal”

FVARIABLE <name> ( — ) Floating

Define a floating-point variable with the given name. Execution of name will return the address of its data space. Floating-point variables may be stored in a separate region of memory, and subsequent allocations of memory with , or ALLOT may not be contiguous with an FVARIABLE. An FVARIABLE may be initialized with, e.g., F! (see below). “F-variable”

3.8.5 Memory Access

Memory access words similar to those in other parts of a Forth system are pro-

System Functions 107

Forth Programmer’s Handbook

vided for floating-point data types. These words obtain addresses from the data stack, and transfer data to and from the floating-point stack. Named regions for transferring IEEE standard data formats may be defined with phrases such as CREATE ALLOT (not FVARIABLE, because its length in memory is implementation specific).

Glossary

 

 

F!

( f-addr — ); ( F: r — )

Floating

 

Store the floating-point value r at f-addr. In single-stack implementations, f-addr

 

must be on top of the stack. “F-store”

 

F@

( f-addr — ); ( F: — r )

Floating

 

Fetch the value stored at f-addr to the floating-point stack. “F-fetch”

 

DF!

( df-addr — ); ( F: r — )

Floating Ext

 

Store the floating-point value r as a 64-bit IEEE double-precision number at

df-addr, rounding if the internal representation has more precision. In singlestack implementations, df-addr must be on top of the stack. “D-F-store”

DF@ ( df-addr — ); ( F: — r ) Floating Ext

Fetch the 64-bit IEEE double-precision number at df-addr, convert to internal representation, and place on the floating-point stack, rounding if the internal representation has less than 64-bit precision. “D-F-fetch”

SF!

( sf-addr — ); ( F: r — )

Floating Ext

 

Store the floating-point value r as a 32-bit IEEE single-precision number at

sf-addr, rounding if the internal representation has more than 32-bit precision. In single-stack implementations, sf-addr must be on top of the stack. “S-F-store”

SF@ ( sf-addr — ); ( F: — r ) Floating Ext

Fetch the 32-bit IEEE single-precision number at sf-addr, convert to internal representation, and place on the floating-point stack, rounding if the internal representation has less than 32-bit precision. “S-F-fetch”

3.8.6 Floating-Point Stack Operators

A set of floating-point stack operators is provided, corresponding generally to

108 System Functions

Forth Programmer’s Handbook

the operators for the integer data stack. Operators are also provided for exchanging values between the data and floating-point stacks. Before coding complicated floating-point stack maneuvers, check your particular system’s maximum floating-point stack depth; it may be small. On systems that keep floating-point numbers on the data stack, take care with the order of floatingpoint and integer operations. These operators function as described, even if the system implements the floating-point stack on the data stack.

Glossary

 

 

D>F

( d — ); ( F: — r )

Floating

 

Convert a double-precision integer d to internal floating-point representation r

 

and place on the floating-point stack. “D-to-F”

 

F>D

( — d ); ( F: r — )

Floating

 

Convert a floating-point number r to a double-precision integer d, discarding

 

the fractional part, and place on the data stack. “F-to-D”

 

FDEPTH

( — +n )

Floating

 

Return +n, the number of values on the floating-point stack. If floating-point

 

numbers are kept on the data stack, +n is the maximum number of possible

 

floating-point values, given the current data stack depth in cells. “F-depth”

FDROP

( F: r — )

Floating

 

Drop the top item on the floating-point stack. “F-drop”

 

FDUP

( F: r — r r )

Floating

 

Duplicate the top item on the floating-point stack. “F-dupe”

 

FOVER

( F: r1 r2 — r1 r2 r1 )

Floating

 

Copy r1 to the top of the floating-point stack. “F-over”

 

FROT

( F: r1 r2 r3 — r2 r3 r1 )

Floating

 

Rotate the top three items on the floating-point stack. “F-rote”

 

FSWAP

( F: r1 r2 — r2 r1 )

Floating

 

Exchange the top two items on the floating-point stack. “F-swap”

 

System Functions 109

Forth Programmer’s Handbook

3.8.7 Floating-Point Arithmetic

The words in this section implement arithmetic on the floating-point stack. All operations are carried out to the full precision of the implementation-specific representation of a floating-point number.

Glossary

F*

( F: r1 r2 — r3 )

Floating

 

Multiply r1 by r2, giving r3. “F-star”

 

F**

( F: r1 r2 — r3 )

Floating Ext

 

Raise r1 to the power r2, giving the result r3. “F-star-star”

F+

( F: r1 r2 — r3 )

Floating

 

Add r1 to r2, giving the sum r3. “f-plus”

 

F-

( F: r1 r2 — r3 )

Floating

 

Subtract r2 from r1, giving the difference r3.

“F-minus”

F/

( F: r1 r2 — r3 )

Floating

 

Divide r1 by r2, giving the quotient r3. “F-slash”

FABS

( F: r1 — r2 )

Floating Ext

 

Return r2, the absolute value of r1. “F-abs”

 

FLOOR

( F: r1 — r2 )

Floating Ext

 

Round r1 to an integral value, rounding toward negative infinity, giving r2.

 

“floor”

 

FMAX

( F: r1 r2 — r3 )

Floating

 

Return r3, the greater of r1 and r2. “F-max”

 

FMIN

( F: r1 r2 — r3 )

Floating

 

Return r3, the lesser of r1 and r2. “F-min”

 

FNEGATE

( F: r1 — r2 )

Floating

 

Return r2, the negation of r1. “F-negate”

 

110 System Functions

Соседние файлы в предмете Электротехника