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

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

#563: Initial testcase.

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1#include <stdio.h>
2#include <float.h>
3
4#define JSDOUBLE_HI32_SIGNBIT 0x80000000
5#define JSDOUBLE_HI32_EXPMASK 0x7ff00000
6#define JSDOUBLE_HI32_MANTMASK 0x000fffff
7#define JSVAL_INT_POW2(n) ((unsigned long)1 << (n))
8#define JSVAL_INT_MAX (JSVAL_INT_POW2(30) - 1)
9#define JSVAL_INT_MIN ((unsigned long)1 - JSVAL_INT_POW2(30))
10
11typedef unsigned uint32;
12typedef uint32 jsuint;
13typedef int jsint;
14
15
16#define JSDOUBLE_HI32(x) (((uint32 *)&(x))[1])
17#define JSDOUBLE_LO32(x) (((uint32 *)&(x))[0])
18
19#define JSDOUBLE_IS_NEGZERO(d) (JSDOUBLE_HI32(d) == JSDOUBLE_HI32_SIGNBIT && \
20 JSDOUBLE_LO32(d) == 0)
21#define JSDOUBLE_IS_FINITE(x) \
22 ((JSDOUBLE_HI32(x) & JSDOUBLE_HI32_EXPMASK) != JSDOUBLE_HI32_EXPMASK)
23
24#define JSDOUBLE_IS_INT(d, i) (JSDOUBLE_IS_FINITE(d) \
25 && !JSDOUBLE_IS_NEGZERO(d) \
26 && ((d) == (i = (jsint)(d))))
27
28#define INT_FITS_IN_JSVAL(i) ((jsuint)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
29
30
31int js_NewNumberValue(void *cx, double d, int *rval)
32{
33 int i;
34#if 1
35 if ( JSDOUBLE_IS_INT(d, i)
36 && INT_FITS_IN_JSVAL(i))
37 return 1;
38#else
39 if (((((unsigned *)&d)[1]) & JSDOUBLE_HI32_EXPMASK) != JSDOUBLE_HI32_EXPMASK )
40 if ( !((((unsigned *)&d)[1]) == JSDOUBLE_HI32_SIGNBIT && (((unsigned *)&d)[0]) == 0))
41 if (d == (i = (int)d))
42 if ((unsigned long)((i)+JSVAL_INT_MAX) <= 2*JSVAL_INT_MAX)
43 return 1;
44#endif
45 return 0;
46}
47
48
49int main()
50{
51 double rd1 = 0.0;
52 double rd2 = 2.147746133e9;
53 double rd3 = 5.147746133e9;
54 int l;
55 _control87(0x262, 0xFFF);
56 js_NewNumberValue(NULL, rd1, &l);
57 js_NewNumberValue(NULL, rd2, &l);
58 js_NewNumberValue(NULL, rd3, &l);
59 return 0;
60}
61
Note: See TracBrowser for help on using the repository browser.