www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - float -> ulong conversion bug

reply Nick <Nick_member pathlink.com> writes:
In a nutshell:











Output:
12
12
12
0

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

Nick
Aug 06 2004
parent reply "Walter" <newshound digitalmars.com> writes:
It works when I try it. -Walter
Aug 09 2004
parent reply Nick <Nick_member pathlink.com> writes:
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
Aug 10 2004
next sibling parent Ben Hinkle <bhinkle4 juno.com> writes:
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.
Aug 10 2004
prev sibling parent reply "Walter" <newshound digitalmars.com> writes:
Ah, on linux. I'll check it out.
Aug 10 2004
parent Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
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
Jan 18 2005