kjs Library API Documentation

simple_number.h

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2003 Apple Computer, Inc
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public License
00017  *  along with this library; see the file COPYING.LIB.  If not, write to
00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019  *  Boston, MA 02111-1307, USA.
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
KDE Logo
This file is part of the documentation for kjs Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:33:09 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003