~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/fplib/mul-03.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test of multiplication. Overflow.
2
 
   $Id: mul-03.c,v 1.1 2007/02/05 21:35:58 dmix Exp $
3
 
 */
4
 
#include <stdio.h>
5
 
#include <stdlib.h>
6
 
#include "progmem.h"
7
 
 
8
 
union lofl_u {
9
 
    long lo;
10
 
    float fl;
11
 
};
12
 
 
13
 
volatile union lofl_u v = { .lo = 1 };
14
 
 
15
 
PROGMEM const struct {          /* Table of test cases:  x * y = z      */
16
 
    union lofl_u x, y, z;
17
 
} t[] = {
18
 
 
19
 
    { { .fl = 0x0.ffffffp64 }, { .fl = 0x0.ffffffp64 }, { 0x7f7ffffe }  },
20
 
    { { .fl = 0x0.800000p65 }, { .fl = 0x0.ffffffp64 }, { 0x7f7fffff }  },
21
 
    { { .fl = 0x0.800000p65 }, { .fl = 0x0.800000p65 }, { 0x7f800000 }  },
22
 
    { { .fl = 0x0.800001p65 }, { .fl = 0x0.800000p65 }, { 0x7f800000 }  },
23
 
    { { .fl = 0x0.800000p65 }, { .fl = 0x0.800001p65 }, { 0x7f800000 }  },
24
 
    { { .fl = 0x0.800001p65 }, { .fl = 0x0.800001p65 }, { 0x7f800000 }  },
25
 
 
26
 
    { { 0x7f7fffff }, { 0x7f7fffff }, { 0x7f800000 }    },
27
 
    { { 0x7f7fffff }, { 0xff7fffff }, { 0xff800000 }    },
28
 
    { { 0xff7fffff }, { 0x7f7fffff }, { 0xff800000 }    },
29
 
    { { 0xff7fffff }, { 0xff7fffff }, { 0x7f800000 }    },
30
 
};
31
 
 
32
 
void x_exit (int index)
33
 
{
34
 
#ifndef __AVR__
35
 
    fprintf (stderr, "t[%d]:  %#lx\n", index - 1, v.lo);
36
 
#endif
37
 
    exit (index ? index : -1);
38
 
}
39
 
 
40
 
int main ()
41
 
{
42
 
    union lofl_u x,y,z;
43
 
    int i;
44
 
    
45
 
    for (i = 0; i < (int) (sizeof(t) / sizeof(t[0])); i++) {
46
 
        x.lo = pgm_read_dword (& t[i].x);
47
 
        y.lo = pgm_read_dword (& t[i].y);
48
 
        z.lo = pgm_read_dword (& t[i].z);
49
 
        v.fl = x.fl * y.fl;
50
 
        /* Comparison is integer to verify the zero sign.       */
51
 
        if (v.lo != z.lo)
52
 
            x_exit (i+1);
53
 
    }
54
 
    return 0;
55
 
}