Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.UUCP (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Single precision math in C Keywords: float, single precision Message-ID: <684@auspex.UUCP> Date: 12 Dec 88 17:33:37 GMT References: <88Dec10.135843est.10521@ephemeral.ai.toronto.edu> Reply-To: guy@auspex.UUCP (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 39 >I am looking for more or less portable ways to get C compilers to perform >floating point math for intrinsic functions like *, /, etc. If the operands of the operand in question are both floating point (or one is floating point, which causes the other to be converted to floating point), any valid C compiler will, obviously, generate code to perform floating point math. However... >Because some of the machines that I run on have no floating point processor, >it is useful to be able to force single-precision math for speed. ...if you want to get the compiler to perform *single-precision* floating point math, there's no way within the C language as specified by K&R to get this, since it specifies that floating point math is done in double precision. However, in the draft ANSI C standard, specifying "float" rather than "double" operands permits the compiler to do single-precision math. (I don't have the standard handy, so I don't know whether it *requires* the compiler to do single-precision math.) Furthermore... >Is there a reasonably portable way to do what I want? I would like to >make sure that I can recompile my programs on (at least) Sun 4s running >SunOS 4.0. ...on some C implementations, there is a compiler option to request that arithmetic involving "float"s but no "double"s be performed in single precision. On Sun machines (Sun-2, Sun-3, Sun-4; the manual page lists them but not the Sun386i) under 4.0 and, I think, earlier releases, you can give the compiler the "-fsingle" flag. Similar flags may exist under other implementations. There is no portable way of doing this; i.e., there's no way to write your code so that *every* C implementation in existence will do single-precision math, because not all of the ones written to the older standard have a "single-precision floating point" flag.