00001 // $Id: f16spec.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // fixed16 code that will probably need changing between platforms 00100 // (portable code can be found in fixed16.cpp). This is the Windows version 00101 00102 00103 00104 #include "camtypes.h" 00105 #include "f16spec.h" 00106 //#include "source.h" 00107 #include <math.h> 00108 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 //#include "andy.h" 00110 00111 DECLARE_SOURCE("$Revision: 1282 $"); 00112 00113 #define TORADIANS(x) ((x)/180.0*PI) 00114 00115 /******************************************************************************************** 00116 00117 > BOOL MathCoprocInstalled; 00118 00119 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00120 Created: 11/6/93 00121 SeeAlso: InitMaths() 00122 Purpose: 00123 Flag used to determine if there is a maths coprocessor present. Its default setting 00124 is FALSE i.e. there is no coprocessor installed. This is mainly used to hint GDraw 00125 how to do things most efficiently. 00126 00127 Errors: None. 00128 00129 ********************************************************************************************/ 00130 00131 static BOOL MathCoprocInstalled = FALSE; 00132 00133 // set this to 1 for the test. Disabled because we have yet to get a Pentium to try it on 00134 #define PENTIUM_TEST 0 00135 00136 00137 #if PENTIUM_TEST 00138 // Pentium FDIV bug test code 00139 // 00140 // Here is a simple test that will reproduce the bug, if present; 00141 // if this gives "256.000000" as result, your system is affected; on a 486, 00142 // this gives "0.000000". The fn returns true if the FPU is OK 00143 00144 // (Note we have never seen this check go off as we have no Pentium machines) 00145 00146 static volatile double IFPBFFOd0=0; 00147 00148 static volatile double * IsFloatingPointBugFreeFoolOptimiser(volatile double * pdbl) 00149 { 00150 if (pdbl) pdbl++; 00151 IFPBFFOd0 = *(--pdbl); 00152 return (pdbl); // This function just returns its own value. 00153 } 00154 00155 // (This code obtained by Alex from somewhere on the net) 00156 00157 static BOOL IsFloatingPointBugFree() 00158 { 00159 volatile double *w,*x,*y,*z; 00160 00161 volatile double wd,xd,yd,zd; 00162 00163 w=&wd; 00164 x=&xd; 00165 y=&yd; 00166 z=&zd; 00167 00168 w=IsFloatingPointBugFreeFoolOptimiser(w); 00169 x=IsFloatingPointBugFreeFoolOptimiser(x); 00170 y=IsFloatingPointBugFreeFoolOptimiser(y); 00171 z=IsFloatingPointBugFreeFoolOptimiser(z); 00172 00173 (*x) = 4195835.0; 00174 (*y) = 3145727.0; 00175 (*z) = ((*x)/(*y)); 00176 00177 w=IsFloatingPointBugFreeFoolOptimiser(w); 00178 x=IsFloatingPointBugFreeFoolOptimiser(x); 00179 y=IsFloatingPointBugFreeFoolOptimiser(y); 00180 z=IsFloatingPointBugFreeFoolOptimiser(z); 00181 00182 (*z) = (*z) * (*y); 00183 00184 w=IsFloatingPointBugFreeFoolOptimiser(w); 00185 x=IsFloatingPointBugFreeFoolOptimiser(x); 00186 y=IsFloatingPointBugFreeFoolOptimiser(y); 00187 z=IsFloatingPointBugFreeFoolOptimiser(z); 00188 00189 (*w) = (*x) - (*z); 00190 00191 w=IsFloatingPointBugFreeFoolOptimiser(w); 00192 x=IsFloatingPointBugFreeFoolOptimiser(x); 00193 y=IsFloatingPointBugFreeFoolOptimiser(y); 00194 z=IsFloatingPointBugFreeFoolOptimiser(z); 00195 00196 return ((*w)<128.0); 00197 } 00198 #endif // PENTIUM_TEST 00199 00200 00201 /******************************************************************************************** 00202 00203 > BOOL IsMathCoprocInstalled() 00204 00205 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> 00206 Created: 19/1/95 00207 Returns: TRUE if the hardware supports a real FPU, FALSE if emulated. 00208 Purpose: Gives a hint to those that need to know things about FPU performance. 00209 Errors: None. 00210 00211 ********************************************************************************************/ 00212 00213 BOOL IsMathCoprocInstalled() 00214 { 00215 #if defined(__WXMSW__) 00216 // the theoretically proper way to detect an FPU is to delve into the reigstry thus: 00217 // NT entry lives at HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\FloatingPointProcessor\0 00218 // W95 entry lives at HKEY_LOCAL_MACHINE\Enum\Root\*PNP0C01\0000NDP (M7 liable to change) 00219 // W32s is only available by thunking to WinFlags() (ug). 00220 // Instead, we use a tiny bit of .asm, as suggested by Mr-Asm himself, Gavin 00221 00222 WORD RegCR0; 00223 _asm 00224 { 00225 smsw RegCR0 // bit 2 of CR0 is the EM bit, set for emulation 00226 } 00227 00228 return (RegCR0 & 4) ? FALSE : TRUE; 00229 #else 00230 return TRUE; 00231 #endif 00232 } 00233 00234 /******************************************************************************************** 00235 00236 > BOOL InitMaths() 00237 00238 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00239 Created: 26/4/93 00240 Inputs: None. 00241 Outputs: None 00242 Returns: A Boolean if initialisation was ok. 00243 Purpose: Initialises the maths class. Windows version tests for maths coprocessor. 00244 Also sets up maths exception vectors. 00245 Errors: None. 00246 00247 ********************************************************************************************/ 00248 00249 BOOL InitMaths() 00250 { 00251 00252 MathCoprocInstalled = IsMathCoprocInstalled(); 00253 00254 #if PENTIUM_TEST 00255 // now check for faulty Pentium 00256 if ( !IsFloatingPointBugFree() ) 00257 { 00258 Error::SetError( _R(IDE_BAD_PENTIUM) ); 00259 InformError(); 00260 } 00261 #endif 00262 00263 return TRUE; 00264 } 00265 00266 00267 /******************************************************************************************** 00268 00269 > FIXED16& FIXED16::Sin() 00270 00271 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00272 Created: 14/5/93 00273 SeeAlso: Fixed16Sin() 00274 Inputs: None. 00275 Outputs: None 00276 Returns: A reference to an FIXED16 with result of sin. Input argument must be in 00277 DEGREES not radians. 00278 Purpose: Performs sine on a FIXED16. 00279 Errors: None. 00280 00281 ********************************************************************************************/ 00282 00283 fixed16& fixed16::Sin() 00284 { 00285 #ifndef WIN32 00286 if (MathCoprocInstalled) //Is MathCoprocessor installed 00287 *this = Fixed16Sin(*this); 00288 else 00289 #endif 00290 *this = sin(TORADIANS(this->MakeDouble())); 00291 00292 ERROR3("Alex doubts whether this routine works"); 00293 00294 return *this; 00295 } 00296 00297 /******************************************************************************************** 00298 00299 > FIXED16& FIXED16::Cos() 00300 00301 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00302 Created: 14/5/93 00303 SeeAlso: Fixed16Cos() 00304 Inputs: None. 00305 Outputs: None 00306 Returns: A reference to an FIXED16 with result of Cos. Input argument must be in 00307 DEGREES not radians. 00308 Purpose: Performs Cos on a FIXED16. 00309 Errors: None. 00310 00311 ********************************************************************************************/ 00312 00313 fixed16& fixed16::Cos() 00314 { 00315 #ifndef WIN32 00316 if (MathCoprocInstalled) //Is MathCoprocessor installed 00317 *this = Fixed16Cos(*this); 00318 else 00319 #endif 00320 *this = cos(TORADIANS(this->MakeDouble())); 00321 00322 ERROR3("Alex doubts whether this routine works"); 00323 00324 return *this; 00325 }