[DGD]Casting to int

Mikael Lind z94lind at mtek.chalmers.se
Fri Jun 30 15:07:33 CEST 2000


Quoting Felix A. Croes from 12:40, June 30, 2000:

> Kris Van Hees <aedil at alchar.org> wrote:
> 
> > Someone on Viking noticed a rather interesting thing... casting a
> > float to an int actually does rounding, thus (int)0.51 yields 1
> > rather than 0. That seems to be quite different from e.g. C &
> > Java where casting to an integer type truly returns the integer
> > part of the number (truncating the floating point value rather
> > than rounding it up or down). Any particular reason why DGD has
> > taken this rather non-standard approach?

Java was designed to resemble C a lot, so that programmers would feel
instantly at home with it. Hence it doesn't make sense to bring up C
and Java as two programming languages where the respective designers
independently chose truncation over rounding for float to int
conversion.

> I have always thought of this the other way.  It is C which is peculiar,
> and the rest of the world is normal.

The rest of the world is normal? Have another look ... ;)

> Then again, array indexing would have started at 1 if I had had a say
> during that stage of the language's design, so perhaps it is my own
> approach with is inherently non-standard.

I agree that array indices should start at 1. 0 has a low-level
computer connection; the array index as an offset from the first
element. 1 is more suited for mathematic and scientific connections,
as well as human expressions - the first element is element number
one.

With new computer languages moving farther away from their
computer-friendly ancestors and more towards human-friendly aspects,
I think that 1 is better suited as the first index; certainly in a
language like LPC.

By the way, I still miss a boolean type in LPC. :)  It was
successfully introduced in Java, even though Java inherited C's
operators.

// Mikael Lind (Elemel at Igormud)


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list