linux-mips
[Top] [All Lists]

Float / Double issues

To: linux@cthulhu.engr.sgi.com
Subject: Float / Double issues
From: Tim Hockin <thockin@cobaltnet.com>
Date: Mon, 12 Jul 1999 20:09:41 -0700
Organization: Cobalt Networks
Sender: owner-linux@cthulhu.engr.sgi.com
Hey gang - I have what seems to be two seperate issues on Mips/Linux
(cobalt boxes).

1) Programs using doubles with pthreads get corrupted data in the
doubles.
2) Floats and va_arg crash with an FPE

below are two snippets that show these, at least on our boxes.  If
someone could confirm or deny their existence on any other platform?


Tim



#include <stdio.h>
#include <pthread.h>
#include <stdarg.h>

void doit(int, double, unsigned int);
void vait(unsigned int, ...);
void *ptfn(void *);
void doit2(int, int);
void vait2(int, ...);
void *ptfn2(void *);

int main() 
{
        pthread_t pt1;
        double d1 = 1.234; 

        printf("Without threads: \n");
        ptfn((void *)&d1);
        printf("\n");
        fflush(stdout);

        printf("With threads: \n");
        pthread_create(&pt1, NULL, ptfn, &d1);
        printf("\n");
        fflush(stdout);

        pthread_exit(0);
        return 0;
}

void *ptfn(void *x)
{
        char ar[16];
        unsigned int decimals = 5;
        double d = *(double *)x;

        doit(1, d, decimals);
        vait(decimals, d);
}

void doit(int x, double d, unsigned int ui)
{
        char buff[331];

        sprintf(buff,"double: %.*f",ui,d);
        printf("%s\n", buff);
}

void vait(unsigned int ui, ...)
{
        double d=-10.0;
        va_list va;

        va_start(va, ui);

        printf("double before va_arg: %f\n", d);
        d = va_arg(va, double);
        printf("double after va_arg: %f\n", d);

        va_end(va);

        doit(1, d, ui);
}
#include <stdio.h>
#include <stdarg.h>

void doit(int, float, unsigned int);
void vait(unsigned int, ...);
void *ptfn(void *);

int main() 
{
        float d1 = 1.234; 

        printf("Without threads: \n");
        ptfn((void *)&d1);
        printf("\n");
        fflush(stdout);

        return 0;
}

void *ptfn(void *x)
{
        char ar[16];
        unsigned int decimals = 5;
        float d = *(float *)x;

        doit(1, d, decimals);
        vait(decimals, d);
}

void doit(int x, float d, unsigned int ui)
{
        char buff[331];

        sprintf(buff,"float: %.*f",ui,d);
        printf("%s\n", buff);
}

void vait(unsigned int ui, ...)
{
        float d=-10.0;
        va_list va;

        va_start(va, ui);

        printf("float before va_arg: %f\n", d);
        d = va_arg(va, float);
        printf("float after va_arg: %f\n", d);

        va_end(va);

        doit(1, d, ui);
}
<Prev in Thread] Current Thread [Next in Thread>