🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #6481

Single precision function using C

#6481
From: mau
Date: Fri, 11 Jan 1991 16:26
52 lines
2452 bytes
I am translating from FORTRAN to C a huge numerical program which runs on
a Sun 4 with SunOs 4.1, hoping both to reorder the code and to gain a
little speed. Unfortunately, the C version is much slower. Indeed, the
reason for the slowness lies in the heavy use of exponential and
logarithms, which are performed with single precision routines in Fortran
and double precision routines in C.  As I have no particular stability
problem, I would like to use single precision routines in the C program,
too. While RTFM, I found a series of such routines in the math package: I
tried to make a program, but it does not return the correct answers, as
you can see.

----- program pippo.c (compiled with cc pippo.c -lm) -----

#include <stdio.h>
#include <math.h>
FLOATFUNCTIONTYPE r_exp_();

main()
{
        float * y;
        float x;
        float z;
        FLOATFUNCTIONTYPE x1;

        for (z = 0.; z < 2.01; z += .2) {
        y = &z;
        x = exp(*y);
        x1 = r_exp_(y);
        printf("z = %f  ... ",z);
        printf("double: %f  ... ",x);
        printf("single: %f \n",x1);
        }
}

----- results -----

z = 0.000000  ... double: 1.000000  ... single: 0.007812
z = 0.200000  ... double: 1.221403  ... single: 0.027675
z = 0.400000  ... double: 1.491825  ... single: 0.120912
z = 0.600000  ... double: 1.822119  ... single: 0.788476
z = 0.800000  ... double: 2.225541  ... single: 3.804328
z = 1.000000  ... double: 2.718282  ... single: 14.985019
z = 1.200000  ... double: 3.320117  ... single: 81.949978
z = 1.400000  ... double: 4.055201  ... single: 568.525625
z = 1.600000  ... double: 4.953033  ... single: 1951.812144
z = 1.800000  ... double: 6.049649  ... single: 9005.450408
z = 2.000000  ... double: 7.389058  ... single: 58265.295935

I guess that there is some problem in the stack return, but I do not
absolutely know which error I make ...

Regards,    .mau.
Technical Details
Message-ID: <1224@brchh104.bnr.ca>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!cunews!bnrgate!brtph3!brchh104!brchs1!bnr.ca!rice.edu!sun-spots-request
From: mau@alice.CSELT.STET.IT
Newsgroups: comp.sys.sun
Subject: Single precision function using C
Keywords: Miscellaneous
Message-ID: <1224@brchh104.bnr.ca>
Date: 11 Jan 91 16:26:34 GMT
Sender: news@brchh104.bnr.ca
Organization: Sun-Spots
Lines: 52
Approved: Sun-Spots@rice.edu
X-Sun-Spots-Digest: Volume 10, Issue 19, message 9
X-Note: Submissions: sun-spots@rice.edu, Admin: sun-spots-request@rice.edu