Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!husc6!linus!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP (der Mouse) Newsgroups: comp.lang.c Subject: Re: C and Floating Point Message-ID: <742@mcgill-vision.UUCP> Date: Sun, 12-Apr-87 05:56:22 EST Article-I.D.: mcgill-v.742 Posted: Sun Apr 12 05:56:22 1987 Date-Received: Sun, 19-Apr-87 10:19:48 EST References: <15958@sun.uucp> <5716@brl-smoke.ARPA> <1283@dataio.Data-IO.COM> Organization: McGill University, Montreal Lines: 60 Keywords: C Fortran Floating Point In article <1283@dataio.Data-IO.COM>, bright@dataio.Data-IO.COM (Walter Bright) writes: > How about allowing numbers to be specified in binary radix, as in > 0b00110101 ? [...] It seems odd that decimal, octal, hex, floating > and ascii formats are supported, but not binary in a language > supposedly designed for bit twiddling! Good idea. I've often wished for this. > As a corollary, support %b in printf and scanf. This will get dreadfully confusing. At least in BSD UNIX, there is already a %b in the kernel's version of printf; it is designed for printing device register bits. For example, this (hypotheical) error message hw3c: hard error sn12345: csr=402 ers=1002 might have been produced by (yes, I know it would really call harderr(), be quiet, this is an example!) the following printf() call: printf( "hw%d%c: hard error sn%d: csr=%b ers=%b\n", unit >> 3, "abcdefgh"[unit&7], blkno, hwdev->csr, "\10\2IE\3GO\5READY\11ERR", hwdev->ers, "\10\1SOFT\2HARD\4TIMEO\12CRC\13NODATA" ); > Also, support specifying floating numbers in hex radix. This would > avoid horrible kludges like: > [horrible kludge, using pointer punning] > The syntax would be: > double def = 0x1324.5E678e+0x12; > double abc = -0x.1B4F; > def prescribes a mantissa of 0x12345E678 and an exponent of > (4*16+0x12). > Note that a + or - would be required before the exponent, to > distinguish the e from the digit e. Not good enough. "double def = 0x1234e+0x12" can be read as either "mantissa 1234, exponent 4*16+0x12" or "value 0x12360" (sum of 0x1234e and 0x12). > Such syntax would be very useful to those of us writing numerical > subroutines. Numerical analysis books frequently give the constants > to use specified in hex or octal, so as to control the resulting > values exactly. And if you are on a BCD machine, rather than a binary machine? Or, though I doubt any such actually exist, a ternary machine? I guess there just aren't any good numerical algorithms for BCD or ternary machines....:-) der Mouse (mouse@mcgill-vision.uucp)