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

Forth Programmer’s Handbook

SFLOAT+

( sf-addr1 — sf-addr2 )

Floating Ext

 

Add the size in bytes of a 32-bit IEEE single-precision floating-point number to

 

sf-addr1, giving sf-addr2. “S-float-plus”

 

SFLOATS

( n1 — n2 )

Floating Ext

 

Return n2, the size in bytes of n1 32-bit IEEE single-precision floating-point

 

numbers. “S-floats”

 

3.8.11

Custom I/O

 

 

 

 

 

The input number conversion routines in the text interpreter and the standard output words F., FE., and FS. can be used for most floating-point I/O, but there are cases where more control over the process is desired. The words >FLOAT (for input) and REPRESENT (for output) can be used as the basis for custom I/O routines. The input word >FLOAT is more flexible than the text interpreter routines (for example, an exponent marker E or e is not required), but it cannot vector between integers and floating-point numbers; it assumes that the input string is to be converted as a floating-point number, if at all possible. >FLOAT is defined broadly to permit valid floating-point input from many standard programming environments.

Glossary

 

 

>FLOAT

( c-addr u — true | false ); ( F: — r | )

Floating

Attempt to convert the string specified by starting address c-addr and length u to internal floating-point representation. If the conversion is successful, its floatingpoint value r and true are returned. If it was not successful, only false is returned. A string of blanks should be converted as floating-point zero. “to-float”

Nearly any reasonably constructed string will convert. Decimal base is assumed. A valid number has a significand and optional exponent. The significand has an optional sign and at least one digit, with or without a decimal point. The exponent, if present, is signified by E, e, D, or d followed by an optional integer (signed or unsigned), or by a plain + or - followed by an optional integer. >FLOAT will convert all the following to valid floating-point numbers:

-1.23e-01 -1 .3 5D -6.12+34 7+3 .456- .006 9+00

116 System Functions

Forth Programmer’s Handbook

REPRESENT ( c-addr u — n flag1 flag2 ); ( F: r — )* Floating

Attempt to convert the significand of the floating-point number r. At c-addr, place an ASCII representation of the u most-significant digits of the significand. The string is to be interpreted as a decimal fraction, with an implied decimal point to the left of the first digit; the first digit is zero only if all digits are zero. Return on the stack the resulting decimal base exponent n, the sign of the floating-point number as flag1 (true if r was negative) and a valid-result flag2 (true if r was in the implementation-defined range of valid floating-point numbers). The significand is rounded to u digits following the round-to-near- est-integer rule, and n is adjusted as necessary after the rounding.

If flag2 is false, n, flag1, and the contents of c-addr are implementation specific. However, the string at c-addr shall consist of displayable characters. For example, a system might return the informative messages +infinity or nan (“not a number”) to c-addr.

*For single-stack systems, the order of the input arguments to REPRESENT is r on the bottom followed by c-addr and u (top).

System Functions 117

Forth Programmer’s Handbook

118 System Functions

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