Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!mit-eddie!genrad!decvax!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: comp.bugs.4bsd,comp.lang.c Subject: Re: Bug converting unsigned to double in BSD 4.[23] Message-ID: <9777@sun.uucp> Date: Mon, 1-Dec-86 15:22:10 EST Article-I.D.: sun.9777 Posted: Mon Dec 1 15:22:10 1986 Date-Received: Tue, 2-Dec-86 02:07:31 EST References: <213@cartan.Berkeley.EDU> <618@hadron.UUCP> Followup-To: comp.bugs.4bsd Organization: Sun Microsystems, Inc. Lines: 45 Summary: Not just VAX, general PCC bug Xref: mnetor comp.bugs.4bsd:41 comp.lang.c:193 > But apparently type is lost or ignored on the VAX, because it then > does a cvtld (convert long to double). This is clever-not-clever > use of the VAX FP instruction set, which doesn't have an unsigned > long data type. Not on 4.3BSD, it doesn't! It generates a "movd", but the constant it moves is "-1.0", not "4.2949...e9". It's probably due to the following bit of bizarre code in "makety" in "trees.c" - that's part of the machine-independent code, so it will affect other machines: if( p->in.op == ICON && p->tn.rval == NONAME){ if( t==DOUBLE||t==FLOAT ){ p->in.op = FCON; if( ISUNSIGNED(p->in.type) ){ p->fpn.dval = /* (unsigned CONSZ) */ p->tn.lval; } else { p->fpn.dval = p->tn.lval; } p->in.type = p->fn.csiz = t; return( clocal(p) ); } } The commented-out cast is rather peculiar. If you uncomment it, it looks like it should work - and it does, at least where I tried it. > The 68K calls a subroutine: > jbsr dpufloat > which comprehends and translates unsigned longs, as dpfloat does > for signed longs. (Doing it in software has occasional advantages > over doing it in hardware.) *Our* 68Ks don't do this - they do the conversion at compile time, as they should! (Although our compiler currently generates code that does the same wrong thing that the code generated by the VAX compiler does.) It's not a question of whether it's done in hardware or software; it's a question of whether the compiler does the conversion correctly at compile time or not. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)