source: branches/libc-0.6/testcase/floatingpoint/jsnumexception.c

Last change on this file was 379, checked in by bird, 22 years ago

#563: finally the right testcase.

  • Property cvs2svn:cvs-rev set to 1.4
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1#include <stdio.h>
2#include <float.h>
3#include <signal.h>
4#ifdef OS2
5#define INCL_BASE
6#define INCL_PM
7#include <os2.h>
8#endif
9
10#define JSDOUBLE_HI32_SIGNBIT 0x80000000
11#define JSDOUBLE_HI32_EXPMASK 0x7ff00000
12#define JSDOUBLE_HI32_MANTMASK 0x000fffff
13#define JSVAL_INT_POW2(n) ((unsigned long)1 << (n))
14#define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
15#define JSVAL_INT_MIN ((unsigned long)1 - JSVAL_INT_POW2(30))
16
17typedef unsigned uint32;
18typedef uint32 jsuint;
19typedef int jsint;
20
21
22#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[1])
23#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[0])
24
25#define JSDOUBLE_IS_NEGZERO(d) (JSDOUBLE_HI32(d) == JSDOUBLE_HI32_SIGNBIT && \
26 JSDOUBLE_LO32(d) == 0)
27#define JSDOUBLE_IS_FINITE(x) \
28 ((JSDOUBLE_HI32(x) & JSDOUBLE_HI32_EXPMASK) != JSDOUBLE_HI32_EXPMASK)
29
30#define JSDOUBLE_IS_INT(d, i) (JSDOUBLE_IS_FINITE(d) \
31 && !JSDOUBLE_IS_NEGZERO(d) \
32 && ((d) == (i = (jsint)(d))))
33
34#define INT_FITS_IN_JSVAL(i) ((jsuint)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
35
36
37int js_NewNumberValue(void *cx, double d, int *rval)
38{
39 int i = -1;
40#if 1
41 if ( JSDOUBLE_IS_INT(d, i)
42 && INT_FITS_IN_JSVAL(i))
43 {
44 *rval = i;
45 return 1;
46 }
47
48#else
49 if (((((unsigned *)&d)[1]) & JSDOUBLE_HI32_EXPMASK) != JSDOUBLE_HI32_EXPMASK )
50 if ( !((((unsigned *)&d)[1]) == JSDOUBLE_HI32_SIGNBIT && (((unsigned *)&d)[0]) == 0))
51 if (d == (i = (int)d))
52 if ((unsigned long)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
53 return i;
54#endif
55 *rval = i;
56 return 0;
57}
58
59void sigfun(int sig)
60{
61 printf("SIGFPE!\n");
62}
63
64int main()
65{
66 double rd1 = 0.0;
67 double rd2 = 1.000000000e8;
68 double rd3 = 2.147746133e9;
69 int l = -1;
70#ifdef OS2
71 PPIB ppib;
72 DosGetInfoBlocks(NULL, &ppib);
73 ppib->pib_ultype = 3;
74 WinCreateMsgQueue(WinInitialize(0), 0);
75 WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "blah", "Blah!", 0, MB_OK);
76#else
77 _control87(0x262, 0xFFF);
78#endif
79 signal(SIGFPE, sigfun);
80
81 l = -1;
82 js_NewNumberValue(NULL, rd1, &l);
83 printf("%11d %f\n", l, rd1);
84
85 l = -1;
86 js_NewNumberValue(NULL, rd2, &l);
87 printf("%11d %f\n", l, rd2);
88
89 l = -1;
90 js_NewNumberValue(NULL, rd3, &l);
91 printf("%11d %f\n", l, rd3);
92 return 0;
93}
94
Note: See TracBrowser for help on using the repository browser.