[REBOL] Re: Correct Behaviour? Was False = 2 ????
From: joel:neely:fedex at: 4-Jul-2001 5:27
Ken Anthony wrote:
> ... I say we give the minority a chance here. So lets all
> quiet down and give those folks that want to start indexing
> with some number *other* than one or zero a chance to speak!
> Anyone from the seven crowd have anything to say?
I had considered earlier mentioning that in Pascal (and ADA,
IIRC), one is allowed to specify for each array the bounds of
its subscripts. This can be highly useful in some settings.
As a fairly trivial example, imagine reading a file containing
data on junior-high and high-school students and tallying the
number of students in each grade. (With apologies to our
friends around the world, I'll stick with the US conventions
with which I'm familiar!)
Since those grades are numbered 7 through 12, it would be handy
to be able to create an array containing only those indices, to
avoid wasting space and performing explicit grade-to-index
translation in my code.
Ooops! That example actually started with seven! ;-)
> Does anybody know of a use for negative zero?
IIRC the computers made by CDC back in the 60's and 70's
used 1's-complement arithmetic instead of 2's-complement,
which meant that negative zero was actually a possibility.
This allowed for some interesting and subtle bugs, as
witnessed by the fact that RFC 1624, "Computation of the
Internet Checksum via Incremental Update" (May 1994),
A historical aside: the fact that standard one's
complement arithmetic produces negative zero results
is one of its main drawbacks; it makes for difficulty in
interpretation. In the CDC 6000 series computers ,
this problem was avoided by using subtraction as the
primitive in one's complement arithmetic (i.e.,
addition is subtraction of the complement).
Apparently the current IEEE standard allows it as well.
As for uses...
1) Since it is logically superflouous, one could use -0 as
an indication of "no answer", provided one insured that
no other computation (e.g., -1 * (1 - 1)) could produce
-0 as a result.
true = 1
false = 0
none = -1
NONONONO! (only kidding! ;-)
2) It appears to be a way to crash a Microsoft database! ;-)
"If a SQL Server query returns a negative zero, and the
client application binds the results as a SQL_C_DOUBLE,
the following error is reported to the client:
[Microsoft][ODBC SQL Server Driver]Invalid character
value for cast specification
... SQL Server is returning a negative zero, and the SQL
Server driver is reporting this as an error. To
reproduce the error run the following query:
SELECT 0.0 * -1
... Microsoft has confirmed this to be a problem in
SQL Server 7.0."
Programming languages: compact, powerful, simple ...
Pick any two!