From mboxrd@z Thu Jan 1 00:00:00 1970 From: erik quanstrom Date: Fri, 22 Nov 2013 14:54:29 -0500 To: fausto.saporito@gmail.com, quanstro@quanstro.net, 9fans@9fans.net Message-ID: <390a9731e0c3f617cdfcdf3bd7ee81cb@coraid.com> In-Reply-To: References: <5700548.4Uf9crWo2Z@krypton> <3072040.2Ns7VPtGUt@krypton> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] f2c issue Topicbox-Message-UUID: 8bf739bc-ead8-11e9-9d60-3106f5b1d025 > get_nanbits(unsigned int *b, int k) > { > union { double d; unsigned int z[2]; } u, u1, u2; > > k = 2 - k; > u1.z[k] = u2.z[k] = 0x7ff00000; > u1.z[1-k] = u2.z[1-k] = 0; > u.d = u1.d - u2.d; /* Infinity - Infinity */ <<<<<<<====== this is the > FATAL ERROR. > b[0] = u.z[0]; > b[1] = u.z[1]; > } > > called as getnanbits(nanbits,1) oh, boy. we can assume ieee 754. the pattern you want for the nan is u.hi = 0x7ff80000; /* sign = 0; exp = 1s; msb in signf set */ u.lo = 0; you can use FPdbleword in for regular plan 9 programs, and for ape programs which will take care of this for you. in that case, you'd have void get_nanbits(unsigned int *b, int) { FPdbleword w; assert(sizeof(double) == 8); w.hi = 0x7ff80000; w.lo = 0; memcpy(b, &w, 8); }