Path: utzoo!attcan!uunet!mailrus!ncar!noao!arizona!gudeman From: gudeman@cs.arizona.edu (David Gudeman) Newsgroups: comp.lang.misc Subject: implementing frexp() (was: Compiler Costs) Message-ID: <22838@megaron.cs.arizona.edu> Date: 9 Jul 90 01:16:23 GMT Organization: U of Arizona CS Dept, Tucson Lines: 43 In article <2324@l.cc.purdue.edu> cik@l.cc.purdue.edu (Herman Rubin) writes: [about implementing frexp(x,&n) -- mantissa of a float] >Now I submit it will take a real turkey machine language user to match the >slowness of any program written in C or Fortran, USING ONLY THE OPERATIONS >OF THOSE LANGUAGES. Also, inlining, with n being placed in the register >where it is to be used, is likely to cut the running time by more than >half. In C I would write #include ... frexp(x,&n) If this doesn't produce code as fast as assembly language, then you don't have an optimizing compiler. I'd be surprised if the same doesn't hold for FORTRAN. Basically, your implication that C doesn't have an operation to directly destructure floats is wrong. True, the operation (frexp) is called a library function instead of an operator, but the effect is the same, given a smart enough compiler. There are only so many operator symbols available, and frexp is an obscure feature at best. Also, the definition of frexp is portable. It would work on a machine that didn't use the traditional representation of floats. That's because C is intended to be a portable language. If you don't care about portability, (or programming time, or maintenance time), then by all means use assembler. If you want a C-like language that is as machine dependent as assembler then by all means implement it, but don't expect that it will hold much interest for anyone who doesn't program exclusively for your machine. If you want a machine-independent language that lets you include machine-specific parts for performance improvement, then use C with the asm() feature. It is really quite meaningless to give a challenge as above to do something as efficient as assembly language, and rule out asm() as an option. asm() is provided specifically to allow you to do such things. -- David Gudeman Department of Computer Science The University of Arizona gudeman@cs.arizona.edu Tucson, AZ 85721 noao!arizona!gudeman