Path: utzoo!attcan!uunet!samsung!usc!apple!agate!shelby!portia.stanford.edu!fangchin From: fangchin@portia.Stanford.EDU (Chin Fang) Newsgroups: comp.lang.c Subject: Single and double precision math functions, are same names possible? Summary: How would you design one? Keywords: numerical analysis, math.h, single precision,double Message-ID: <1991Jan13.061801.29334@portia.Stanford.EDU> Date: 13 Jan 91 06:18:01 GMT Expires: Jan 30, 1991 References: <1991Jan13.050236.11634@ux1.cso.uiuc.edu> Organization: AIR, Stanford University Lines: 49 precision, libm.a, UNIX. Not too long ago, Glenn Geers of The Univ. of Sydney published a alternative math libs containing both single precision and double precision lib functions and a header file for Intel i486/386 boxes. These libs are designed for use in SysV/386 UNIX environment or for Sun i386 and use i387 instruction sets fully, therefore are much faster than vendor provided libm.a. I typically see a 50% run time reduction with my codes which are normally FLOPs aplenty. However, if you use these two libs, you must use #include instead of . This is no big deal. Just mv would do. The catch comes in when one wants to use the single precision version of the lib (libffpu.a vs libfpu.a, the later being double precision as traditional C libm.a). Then j0(), erf() etc. have to be written as j0f(), erff() etc. in one's src. This is bearable if one only intends to run codes on i486/386 boxes. But assuming porting src is unavoidable sooner or later, this creates a somewhat unplesant editing job to do. Using a sed script should fix it quite nicely. But I wonder whether C gurus in this group can provide a smart way of avoiding using different function names for single and double precision versions? Of course, if they are not used in a code body at the same time, a marco would do (brutal force however). But if that's not the case, a wrapper probably would do too but too much hassle. You don't want to put a wrapper around each single precision function calls first, and incur more overhead and one more name to handle the second. Put it the other way, can you have both precisions using the same name and just a single header file as though I were still using the standard libm.a and math.h? (So transparent that I would have no need to do extra editing of function names for porting except perhaps a few -D switches for compiliations?) So could some one suggest a good way? Regards Chin Fang Mechanical Engineering Department Stanford University fangchin@portia.stanford.edu ps. please email me if possible. I may not be able to return a thank you note to those using bang (!) address schemes due to my school's mail server's recent problems.