00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#ifndef _KJS_SIMPLE_NUMBER_H_
00024
#define _KJS_SIMPLE_NUMBER_H_
00025
00026
#include <limits.h>
00027
#include <math.h>
00028
#include <string.h>
00029
00030
#define IS_NEGATIVE_ZERO(num) (num == 0.0 && !memcmp(&num,&SimpleNumber::negZero,sizeof(double)))
00031
00032
namespace KJS {
00033
class ValueImp;
00034
00035
class SimpleNumber {
00036
public:
00037
enum { tag = 1, shift = 2, mask = (1 << shift) - 1, sign = 1L << (
sizeof(
long) * 8 - 1 ), max = (1L << ((
sizeof(
long) * 8 - 1) - shift)) - 1, min = -max - 1, imax = (1L << ((
sizeof(
int) * 8 - 1) - shift)) - 1, imin = -imax - 1 };
00038
00039
static inline bool is(
const ValueImp *imp) {
return ((
long)imp & mask) == tag; }
00040
static inline long value(
const ValueImp *imp) {
return ((
long)imp >> shift) | (((
long)imp & sign) ? ~max : 0); }
00041
00042
static inline bool fits(
int i) {
return i <= imax && i >= imin; }
00043
static inline bool fits(
unsigned i) {
return i <= (
unsigned)max; }
00044
static inline bool fits(
long i) {
return i <= max && i >= min; }
00045
static inline bool fits(
unsigned long i) {
return i <= (
unsigned)max; }
00046
static inline bool fits(
double d) {
return d <= max && d >= min && d == (
double)(
long)d &&
00047 !IS_NEGATIVE_ZERO(d); }
00048
static inline ValueImp *make(
long i) {
return (
ValueImp *)((i << shift) | tag); }
00049
00050
static double negZero;
00051
00052 };
00053 }
00054
00055
#endif