2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
26 ===========================================================================
29 #include "precompiled.h"
38 void idToken::NumberValue( void ) {
43 assert( type == TT_NUMBER );
47 // floating point number
48 if ( subtype & TT_FLOAT ) {
49 if ( subtype & ( TT_INFINITE | TT_INDEFINITE | TT_NAN ) ) {
50 if ( subtype & TT_INFINITE ) { // 1.#INF
51 unsigned int inf = 0x7f800000;
52 floatvalue = (double) *(float*)&inf;
54 else if ( subtype & TT_INDEFINITE ) { // 1.#IND
55 unsigned int ind = 0xffc00000;
56 floatvalue = (double) *(float*)&ind;
58 else if ( subtype & TT_NAN ) { // 1.#QNAN
59 unsigned int nan = 0x7fc00000;
60 floatvalue = (double) *(float*)&nan;
64 while( *p && *p != '.' && *p != 'e' ) {
65 floatvalue = floatvalue * 10.0 + (double) (*p - '0');
70 for( m = 0.1; *p && *p != 'e'; p++ ) {
71 floatvalue = floatvalue + (double) (*p - '0') * m;
81 else if ( *p == '+' ) {
89 for ( pow = 0; *p; p++ ) {
90 pow = pow * 10 + (int) (*p - '0');
92 for ( m = 1.0, i = 0; i < pow; i++ ) {
103 intvalue = idMath::Ftol( floatvalue );
105 else if ( subtype & TT_DECIMAL ) {
107 intvalue = intvalue * 10 + (*p - '0');
110 floatvalue = intvalue;
112 else if ( subtype & TT_IPADDRESS ) {
114 while( *p && *p != ':' ) {
117 intvalue = intvalue * 10;
123 intvalue = intvalue * 10 + (*p - '0');
129 intvalue = intvalue * 10;
132 floatvalue = intvalue;
134 else if ( subtype & TT_OCTAL ) {
135 // step over the first zero
138 intvalue = (intvalue << 3) + (*p - '0');
141 floatvalue = intvalue;
143 else if ( subtype & TT_HEX ) {
144 // step over the leading 0x or 0X
148 if (*p >= 'a' && *p <= 'f')
149 intvalue += *p - 'a' + 10;
150 else if (*p >= 'A' && *p <= 'F')
151 intvalue += *p - 'A' + 10;
153 intvalue += *p - '0';
156 floatvalue = intvalue;
158 else if ( subtype & TT_BINARY ) {
159 // step over the leading 0b or 0B
162 intvalue = (intvalue << 1) + (*p - '0');
165 floatvalue = intvalue;
167 subtype |= TT_VALUESVALID;
172 idToken::ClearTokenWhiteSpace
175 void idToken::ClearTokenWhiteSpace( void ) {
176 whiteSpaceStart_p = NULL;
177 whiteSpaceEnd_p = NULL;