inconsistent behavior of >FLOAT
- From: Krishna Myneni <krishnamyneni@xxxxxxxxxxxxx>
- Date: Mon, 04 May 2009 07:24:36 -0500
The word >FLOAT from the floating point word set appears to have inconsistent behavior on different Forth systems for the case of a string with zero length:
s" " >FLOAT
There is exactly one space between the quote characters in the above line, which should represent a string of zero length.
The return value on top of the data stack is a flag, with true indicating that the string represents a valid floating point number. Values of the resulting flag in recent versions of various Forth systems are:
gforth TRUE
PFE TRUE
VFX Forth FALSE ; using Hfp387.fth
Below is the DPANS94 spec for >FLOAT. Should the specification be made more precise with respect to a string of zero length? I suspect that C's atof() function will return a zero, while the C function strtod() will flag an error.
Krishna
-----------
12.6.1.0558 >FLOAT
to-float FLOATING
( c-addr u -- true | false ) ( F: -- r | )
or ( c-addr u -- r true | false)
An attempt is made to convert the string specified by c-addr and u to internal floating-point representation. If the string represents a valid floating-point number in the syntax below, its value r and true are returned. If the string does not represent a valid floating-point number only false is returned.
A string of blanks should be treated as a special case representing zero.
The syntax of a convertible string := <significand>[<exponent>]
<significand> := [<sign>]{<digits>[.<digits0>] |
..<digits> }
<exponent> := <marker><digits0>
<marker> := {<e-form> | <sign-form>}
<e-form> := <e-char>[<sign-form>]
<sign-form> := { + | - }
<e-char> := { D | d | E | e }
See: A.12.6.1.0558 >FLOAT
------------
Note: A.12.6.1.0558 does not mention the zero length string case.
.
- Follow-Ups:
- Re: inconsistent behavior of >FLOAT
- From: Stephen Pelc
- Re: inconsistent behavior of >FLOAT
- From: Marcel Hendrix
- Re: inconsistent behavior of >FLOAT
- From: Elizabeth D Rather
- Re: inconsistent behavior of >FLOAT
- From: Stephen Pelc
- Re: inconsistent behavior of >FLOAT
- From: Bernd Paysan
- Re: inconsistent behavior of >FLOAT
- Prev by Date: Re: forth in forth
- Next by Date: Re: inconsistent behavior of >FLOAT
- Previous by thread: A simple text macro processor with Forth-like features
- Next by thread: Re: inconsistent behavior of >FLOAT
- Index(es):
Relevant Pages
|