8.6.1.1140 D>S d-to-s DOUBLE

( d -- n )

n is the equivalent of d. An ambiguous condition exists if d lies outside the range of a signed single-cell number.

See:

Rationale:

There exist number representations, e.g., the sign-magnitude representation, where reduction from double- to single-precision cannot simply be done with DROP. This word, equivalent to DROP on two's complement systems, desensitizes application code to number representation and facilitates portability.

Testing:

T{    1234  0 D>S ->  1234   }T
T{   -1234 -1 D>S -> -1234   }T
T{ MAX-INT  0 D>S -> MAX-INT }T
T{ MIN-INT -1 D>S -> MIN-INT }T

ContributeContributions

JimPetersonavatar of JimPeterson [199] Inaccurate Test Cases?Suggested Testcase2021-05-14 20:22:32

The test cases appear to assume a two's complement implementation of doubles even though the rationale for the existence of this word is that the implementation might not be two's complement. A similar situation exists for S>D, whose entry says even less about the possibility of signed-magnitude doubles. I think the only viable test cases would have S>D followed by D>S. Without the presence of D>S in the core word set, I can't think of any feasible test case for S>D that does not rely on the double word set.

Alternatively, the standard could state that the implementation of doubles must be two's complement, and make this word obsolete. Are there any systems in use that don't use two's complement?

AntonErtlavatar of AntonErtl

A proposal to standardize two's complement representation of negative numbers has been approved by the committee in 2015, so the next standard will contain that. No Forth systems that use other representations of negative integers are known.

AntonErtlavatar of AntonErtl

On behalf of the committee: Since we have decided to standardize 2s-complement arithmetic, the test case is correct for the next standard. We are not going to correct this test case for Forth-2012. In the unlikely case that someone wants to write a Forth-2012 system for a sign-magnitude or 1s-complement system, the present discussion should give enough warning that these test cases will not work for them.

Closed
Reply New Version