source: trunk/testcase/floatingpoint/jsnumexception.c@ 1251

Last change on this file since 1251 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
RevLine 
[374]1#include <stdio.h>
2#include <float.h>
[376]3#include <signal.h>
[379]4#ifdef OS2
5#define INCL_BASE
6#define INCL_PM
7#include <os2.h>
8#endif
[374]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{
[375]39 int i = -1;
[374]40#if 1
41 if ( JSDOUBLE_IS_INT(d, i)
42 && INT_FITS_IN_JSVAL(i))
[375]43 {
44 *rval = i;
45 return 1;
46 }
47
[374]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)
[375]53 return i;
[374]54#endif
[375]55 *rval = i;
[374]56 return 0;
57}
58
[376]59void sigfun(int sig)
60{
61 printf("SIGFPE!\n");
62}
[374]63
64int main()
65{
66 double rd1 = 0.0;
[375]67 double rd2 = 1.000000000e8;
68 double rd3 = 2.147746133e9;
69 int l = -1;
[379]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
[374]77 _control87(0x262, 0xFFF);
[379]78#endif
[376]79 signal(SIGFPE, sigfun);
[375]80
81 l = -1;
[374]82 js_NewNumberValue(NULL, rd1, &l);
[375]83 printf("%11d %f\n", l, rd1);
84
85 l = -1;
[374]86 js_NewNumberValue(NULL, rd2, &l);
[375]87 printf("%11d %f\n", l, rd2);
88
89 l = -1;
[374]90 js_NewNumberValue(NULL, rd3, &l);
[375]91 printf("%11d %f\n", l, rd3);
[374]92 return 0;
93}
94
Note: See TracBrowser for help on using the repository browser.