Thread overview
float -> ulong conversion bug
Aug 06, 2004
Nick
Aug 09, 2004
Walter
Aug 10, 2004
Nick
Aug 10, 2004
Ben Hinkle
Aug 10, 2004
Walter
Jan 18, 2005
Russ Lewis
August 06, 2004
In a nutshell:

# import std.stdio;
#
# void main()
# {
#   writefln(cast(int) 12.0);
#   writefln(cast(uint) 12.0);
#   writefln(cast(long) 12.0);
#   writefln(cast(ulong) 12.0);
# }

Output:
12
12
12
0

And I was wondering why the square root of every number was zero ;-)

Nick


August 09, 2004
It works when I try it. -Walter


August 10, 2004
In article <cf8hie$t9e$1@digitaldaemon.com>, Walter says...
>
>It works when I try it. -Walter
>

Hmm, that's strange, because it still doesn't work for me. I'm using dmd 0.98 on linux. Can anyone else comfirm?

Nick


August 10, 2004
Nick wrote:

> In article <cf8hie$t9e$1@digitaldaemon.com>, Walter says...
>>
>>It works when I try it. -Walter
>>
> 
> Hmm, that's strange, because it still doesn't work for me. I'm using dmd 0.98 on linux. Can anyone else comfirm?
> 
> Nick

I'm on linux, too, and it reproduces for me.
August 10, 2004
Ah, on linux. I'll check it out.


January 18, 2005
Walter wrote:
> Ah, on linux. I'll check it out.

I am on Linux (Fedora Core 1, DMD 0.110), and have found this problem with casting float->ulong, double->ulong, and real->ulong.  It works when converting to long, however.

> import std.stdio;
>  void main() {
>   double d = 1.0;
>   writefln("double: ",d);
>   writefln("double->float: ", cast(float)d);
>   writefln("double->real:  ", cast(real)d);
>   writefln("double->ulong: ", cast(ulong)d);
>   writefln("double->long:  ", cast(long)d);
>  
>   float f = 2.0;
>   writefln("float: ",f);
>   writefln("float->double: ", cast(double)f);
>   writefln("float->real:   ", cast(real)f);
>   writefln("float->ulong:  ", cast(ulong)f);
>   writefln("float->long:   ", cast(long)f);
>  
>   real r = 3.0;
>   writefln("real: ",r);
>   writefln("real->float:  ", cast(float)r);
>   writefln("real->double: ", cast(double)r);
>   writefln("real->ulong:  ", cast(ulong)r);
>   writefln("real->long:   ", cast(long)r);
> }



This currently prints:

> double: 1
> double->float: 1
> double->real:  1
> double->ulong: 0
> double->long:  1
> float: 2
> float->double: 2
> float->real:   2
> float->ulong:  0
> float->long:   2
> real: 3
> real->float:  3
> real->double: 3
> real->ulong:  0
> real->long:   3