00001 // $Id: ccmaths.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 00100 #include "camtypes.h" 00101 //#include "fixed.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00102 //#include "xlong.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 //#include "ccmaths.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00104 //#include "fixed16.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 00106 DECLARE_SOURCE("$Revision: 1282 $"); 00107 00108 00109 /******************************************************************************************** 00110 00111 > XLONG Mul(const INT32 operand1, const INT32 operand2) 00112 00113 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00114 Created: 26/4/93 00115 Inputs: Two INT32 values 00116 SeeAlso: Xlongasm.h 00117 Outputs: None 00118 Returns: A reference to an xlong with result of multiplication. 00119 Purpose: Multiplication of two 32-bit signed numbers (xlongs). 00120 Errors: None. 00121 00122 ********************************************************************************************/ 00123 /* 00124 Technical notes: 00125 00126 ********************************************************************************************/ 00127 00128 XLONG Mul(const INT32 operand1, const INT32 operand2) 00129 { 00130 XLONG result; 00131 00132 XMul32(operand1, operand2, result); 00133 00134 return result; 00135 } 00136 00137 /******************************************************************************************** 00138 00139 > XLONG Asl (const INT32, UINT32) 00140 00141 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00142 Created: 5/5/93 00143 Inputs: INT32 - value to be shifted 00144 UINT32 - shift count 00145 Outputs: None 00146 Returns: XLONG - shifted number. 00147 Purpose: Performs arithmetic shift left. 00148 Errors: None. 00149 00150 ********************************************************************************************/ 00151 /* 00152 Technical notes: 00153 00154 Using the ASL provided with xlong for now. 00155 00156 ********************************************************************************************/ 00157 00158 XLONG Asl (const INT32 value, UINT32 shift) 00159 { 00160 XLONG result; 00161 00162 result = MakeXLong(value); 00163 00164 return (result << shift); 00165 00166 } 00167 00168 /******************************************************************************************** 00169 00170 > XLONG Asr (const INT32, UINT32) 00171 00172 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00173 Created: 5/5/93 00174 Inputs: INT32 - value to be shifted 00175 UINT32 - shift count 00176 Outputs: None 00177 Returns: XLONG - shifted number. 00178 Purpose: Performs arithmetic shift right. 00179 Errors: None. 00180 00181 ********************************************************************************************/ 00182 /* 00183 Technical notes: 00184 00185 Using the ASR provided with xlong for now. 00186 00187 ********************************************************************************************/ 00188 00189 XLONG Asr (const INT32 value, UINT32 shift) 00190 { 00191 return ( XLONG(value) >> shift); 00192 } 00193 00194 /******************************************************************************************** 00195 00196 > INT32 MulDiv32By32(const INT32 operand1, const INT32 operand2, const INT32 operand3) 00197 00198 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00199 Created: 5/5/93 00200 SeeAlso: Xlongasm.h 00201 Inputs: operand1 - multiplicand 1 00202 operand2 - multiplicand 2 00203 operand3 - divisor 00204 Outputs: None 00205 Returns: INT32 - result of multiply-divide. 00206 Purpose: Multiplies two 32-bit values and divides the result by another 32-bit value. 00207 Errors: None. 00208 00209 ********************************************************************************************/ 00210 /* 00211 Technical notes: 00212 00213 ********************************************************************************************/ 00214 00215 INT32 MulDiv32By32(const INT32 operand1, const INT32 operand2, const INT32 operand3) 00216 { 00217 return Mul32Div32( operand1, operand2, operand3 ); 00218 } 00219 00220 /********************************************************************************************** 00221 00222 > XLONG MakeXLong (const INT32 operand) 00223 00224 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00225 Created: 5/5/93 00226 SeeAlso: Xlongasm.h 00227 Inputs: Long value to be converted. 00228 Outputs: None. 00229 Returns: an xlong value. 00230 Purpose: To convert an INT32 value to an xlong. 00231 Errors: None. 00232 00233 **********************************************************************************************/ 00234 /* 00235 Technical notes: 00236 00237 **********************************************************************************************/ 00238 00239 XLONG MakeXLong (const INT32 operand) 00240 { 00241 return XLONG(operand); 00242 } 00243 00244 /********************************************************************************************** 00245 00246 > XLONG MakeXLong (const double operand) 00247 00248 Author: Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 00249 Created: 5/5/93 00250 SeeAlso: Xlongasm.h 00251 Inputs: double value to be converted. 00252 Outputs: None. 00253 Returns: an xlong value. 00254 Purpose: To convert a double value to an xlong. 00255 Errors: None. 00256 00257 **********************************************************************************************/ 00258 /* 00259 Technical notes: 00260 00261 **********************************************************************************************/ 00262 00263 XLONG MakeXLong(const double operand) 00264 { 00265 xlong result; 00266 00267 DoubleToXlong(operand, result); 00268 00269 return result; 00270 } 00271 /******************************************************************************************** 00272 00273 > FIXED16 Div32By32( INT32 arg1, INT32 arg2 ) 00274 00275 Author: Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com> 00276 Created: 11/5/93 00277 Inputs: two signed 32-bit numbers 00278 Outputs: None 00279 Returns: FIXED16 result of arg1/arg2 00280 Scope: Private to the CCMATHS library. 00281 Purpose: Obtain a fixed-point representation of the ratio between two signed 00282 numbers. 00283 Errors: None. Div0 and overflow will create a div0 exception. 00284 See Also: InternalDiv32by32 00285 00286 This fn is inline. 00287 00288 ********************************************************************************************/ 00289 00290 /******************************************************** 00291 00292 < Maths Types 00293 < Maths Conversion Table 00294 < Conversion 00295 00296 comment: 00297 \pard\plain 00298 \trowd \trgaph108\trleft-108 00299 \cellx1593\cellx3294\cellx4995\cellx6696\cellx8397\cellx10098\pard\plain 00300 \qc \intbl \fs20\lang2057 {\b From}{\b }{\b \\}{\b }{\b To}{\b \cell }{\b INT32}{\b \cell } 00301 {\b INT32}{\b \cell }{\b XLONG}{\b \cell }{\b FIXED16}{\b \cell }{\b double}{\b \cell }\row 00302 \qc\intbl {\b INT32}{\b \cell }-\cell auto 00303 \cell constructor 00304 \par operator=\cell constructor 00305 \par operator=\cell auto\cell \pard \intbl \row \pard \qc\intbl {\b INT32}{\b \cell } 00306 built-in cast\cell -\cell MakeXlong() 00307 \par constructor 00308 \par operator= 00309 \par cast operator\cell operator= 00310 \par constructor\cell auto\cell \pard \intbl \row \pard \qc\intbl {\b XLONG}{\b \cell } 00311 MakeInt()\cell MakeLong()\cell -\cell MakeFixed16()\cell MakeDouble()\cell \pard 00312 \intbl \row \pard \qc\intbl {\b FIXED16}{\b \cell }MakeInt()\cell MakeLong()\cell 00313 MakeXlong()\cell -\cell MakeDouble()\cell \row \qc\intbl {\b double} 00314 {\b \cell }explicit cast\cell explicit cast\cell MakeXlong()\cell operator= 00315 \par constructor\cell -\cell \pard \intbl \row \pard 00316 00317 ******************************************************************/