Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 24, 2004 Implicit casting | ||||
---|---|---|---|---|
| ||||
I think that implicit casting from greater space to lesser space should be not allowed, because imho it isn't logically correct. for example: unit -> int // ok int -> uin // error float -> double // ok double -> float // error int -> float // ok float -> int // error -- Sark7 |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | I couldn't agree more "Sark7" <sark7@mail333.com> wrote in message news:opr3ux0xcvut8jae@news.digitalmars.com... > I think that implicit casting from greater space to lesser space should be not allowed, because imho it isn't logically correct. > > for example: > > unit -> int // ok > int -> uin // error > > float -> double // ok > double -> float // error > > int -> float // ok > float -> int // error > > -- > Sark7 |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | On Tue, 24 Feb 2004 15:58:24 +1100 (02/24/04 15:58:24) , Matthew <matthew.hat@stlsoft.dot.org> wrote: > I couldn't agree more > > > "Sark7" <sark7@mail333.com> wrote in message > news:opr3ux0xcvut8jae@news.digitalmars.com... >> I think that implicit casting from greater space to lesser space should be >> not allowed, because imho it isn't logically correct. >> >> for example: >> >> unit -> int // ok >> int -> uin // error >> >> float -> double // ok >> double -> float // error >> >> int -> float // ok >> float -> int // error >> >> -- >> Sark7 > At the very least, a warning message would be nice. The general principle being that if a implicit cast can possibly cause loss of information at run-time, then the coder should be made aware of it. Excuse my ignorance, but what about the case where two floats are multiplied and the result assigned to a third float. Does D cause the first two floats to be promoted to a double such that the calculated product (temporary result) is a double prior to being assigned to storage? float a,b, c; a = 12.3456789012; b = 23.4567890123; c = a * b; -- Derek -- Derek |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | In article <opr3ux0xcvut8jae@news.digitalmars.com>, Sark7 says... > >I think that implicit casting from greater space to lesser space should be not allowed, because imho it isn't logically correct. > >for example: > >unit -> int // ok >int -> uin // error > >float -> double // ok >double -> float // error > >int -> float // ok >float -> int // error > >-- >Sark7 I thought that was already true. |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Juan C | Juan C wrote:
> I thought that was already true.
But why do you think that this is true? May I cite a recent posting of yours?:
| [...] the language shouldn't prevent the user from making errors.
I cannot find anything illegal in casting into lesser space in that case, that the actual source value fits into the range of the target type.
So long.
|
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derek Parnell | "Derek Parnell" <Derek.Parnell@Psyc.ward> wrote in message news:opr3u0mvnhdeu3pf@news.digitalmars.com... > On Tue, 24 Feb 2004 15:58:24 +1100 (02/24/04 15:58:24) > , Matthew <matthew.hat@stlsoft.dot.org> wrote: > > > I couldn't agree more > > > > > > "Sark7" <sark7@mail333.com> wrote in message news:opr3ux0xcvut8jae@news.digitalmars.com... > >> I think that implicit casting from greater space to lesser space should > >> be > >> not allowed, because imho it isn't logically correct. > >> > >> for example: > >> > >> unit -> int // ok > >> int -> uin // error > >> > >> float -> double // ok > >> double -> float // error > >> > >> int -> float // ok > >> float -> int // error > >> > >> -- > >> Sark7 > > > > At the very least, a warning message would be nice. The general principle being that if a implicit cast can possibly cause loss of information at run-time, then the coder should be made aware of it. > > Excuse my ignorance, but what about the case where two floats are multiplied and the result assigned to a third float. Does D cause the first two floats to be promoted to a double such that the calculated product (temporary result) is a double prior to being assigned to storage? > > float a,b, c; > > a = 12.3456789012; > b = 23.4567890123; > c = a * b; I would expect that to be the case, but I don't know |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | Matthew wrote: >>multiplied and the result assigned to a third float. Does D cause the >>first two floats to be promoted to a double such that the calculated >>product (temporary result) is a double prior to being assigned to storage? >> >> float a,b, c; >> >> a = 12.3456789012; >> b = 23.4567890123; >> c = a * b; >> >> > >I would expect that to be the case, but I don't know > > That would be a very bad idea performance wise, unless the calculation is a compile time one (like would be possible with the example given). -- -Anderson: http://badmama.com.au/~anderson/ |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | Sark7 wrote: [...] > imho it isn't logically correct. That depends on the logic you want to use. Why should it be "logically incorrect" to implicitly cast from a type with fine resolution, small range of values and much space to a type with coarser resolution, broader range of values and less space? [...] > unit -> int // ok > int -> uin // error [...] If you mean `uint' and `int' here, then why should it be "logically correct" to implicitly cast an actual value of `int.max + 1', which can be hold by an `uint', to an `int'? So long. |
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | Sark7 wrote:
> I think that implicit casting from greater space to lesser space should be not allowed, because imho it isn't logically correct.
>
> for example:
>
> unit -> int // ok
> int -> uin // error
>
> float -> double // ok
> double -> float // error
>
> int -> float // ok
> float -> int // error
>
> --
> Sark7
I agree.
|
February 24, 2004 Re: Implicit casting | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sark7 | Sark7 wrote: > I think that implicit casting from greater space to lesser space should be not allowed, because imho it isn't logically correct. > > for example: > > unit -> int // ok But uint's can be greater then int's. I don't think either should be allowed without a cast. > int -> uin // error > > float -> double // ok > double -> float // error > > int -> float // ok > float -> int // error I think float/double to int should also have a forced cast. Most of the time you are using floating point for calculations that need the fraction part and accidental conversion to int can be a real problem. However, I think these things are to late to change now, it's kinda engrained in D now and would cause to many changes in stuff that is already written. -- -Anderson: http://badmama.com.au/~anderson/ |
Copyright © 1999-2021 by the D Language Foundation