Changeset 4062 in Sophya
- Timestamp:
- Apr 27, 2012, 12:26:07 AM (12 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/basetools.h
r4051 r4062 27 27 #include "randtmt32.h" 28 28 #include "randtmt64.h" 29 29 #include "pqnumber.h" 30 #include "pqnumber.h" 31 #include "sunitpcst.h" 30 32 #endif -
trunk/SophyaLib/BaseTools/pqnumber.cc
r4056 r4062 15 15 \code 16 16 // Create a PrimeNumbers object 17 // Create a PrimeNumbers object 17 18 PrimeNumbers primes; 18 // Print the first 15 primes...19 for(size_t k=0; k<15; k++)20 cout << primes(k) << endl;19 // Print the prime numbers from rank 20 to 25 ... 20 cout << " Primes[20...30]: " ; 21 for(size_t k=19; k<30; k++) cout << primes(k) << " "; 21 22 // Print all prime numbers less than some max values 22 uint_8 p max = 223;23 uint_8 p = primes.Next();23 uint_8 p = primes.Next(); uint_8 pmax = 223; 24 cout << endl << " Primes < " << pmax << " : " << endl; 24 25 while (p<pmax) { 25 cout << p << endl;26 26 cout << p << " "; 27 p = primes.Next(); 27 28 } 29 cout << endl; 30 // Compute and print prime factor decomposition: 31 uint_8 nombre=247890; 32 vector<uint_8> pfac=primes.PrimeFactors(nombre, true); 33 cout << " PrimeFactors[" << nombre << "]: "; 34 for(size_t i=0; i<pfac.size(); i++) cout << pfac[i] << " "; 35 cout << endl; 28 36 \endcode 29 37 */ … … 266 274 267 275 \code 268 // Create rational numbers from integers276 // Create rational numbers from pairs of integers 269 277 QNumber q1(3,4), q2(5,6), q3(6,8); 270 278 // Operations and comparsion … … 272 280 cout << q1 << " + " << q2 << " = " << q4 << endl; 273 281 QNumber qa(q1), qb(q2); 274 cout " Test qa==qb : -> " << qa << " ?== " << qb;282 cout << " Test qa==qb : -> " << qa << " ?== " << qb; 275 283 if (qa == qb) cout << " -> true " << endl; 276 284 else cout << " -> false " << endl; 277 285 qb = q3; 278 cout " Test qa==qb : -> " << qa << " ?== " << qb;286 cout << " Test qa==qb : -> " << qa << " ?== " << qb; 279 287 if (qa == qb) cout << " -> true " << endl; 280 288 else cout << " -> false " << endl; -
trunk/SophyaLib/BaseTools/sunitpcst.cc
r4056 r4062 7 7 \class Units 8 8 \ingroup BaseTools 9 Class for representing physical units 9 This class represents physical dimension and units. Static methods return Units 10 objects corresponding to the usual units, such as meter or watt 10 11 11 12 \code 12 // Create .... 13 Units w=Units::watt(); 14 cout << " Power unit (watt) : " << w.Name() << " (" << w << ")" << endl; 15 // define the speed SI unit (m/s) : 16 Units mos = Units::meter()/Units::second() ; 17 cout << " SI speed unit : " << mos << " -> "; mos.Print() ; 18 // mutiple of an existing unit : 19 Units mw=Units::watt().mega(); 20 cout << " Megawatt: " << mw.Name() << " (" << mw << ") -> "; mw.Print() ; 13 21 \endcode 14 22 */ … … 26 34 27 35 /* --Methode-- */ 36 /*! 37 The Units object is created by specifying its name and short name, and the integer powers 38 for the seven SI base physical quantities (length, mass, time \ldots), and the value of the 39 unit in term of the SI unit. 40 */ 28 41 Units::Units(const char* nom, const char* snom, int m, int kg, int s, r_8 val, int A, int K, int mol, int cd) 29 42 : mLength_(m), mMass_(kg), mTime_(s), mCurr_(A), … … 38 51 { 39 52 Set(un); 53 } 54 55 /* --Methode-- */ 56 Units::Units(Units const& un, r_8 scale, const char* nom, const char* snom) 57 { 58 Set(un); 59 mSI_Value_*=scale; 60 mName_=nom; 61 mShortName_=snom; 40 62 } 41 63 … … 179 201 \class PhysQty 180 202 \ingroup BaseTools 181 Class for representing physical quantities and constants 203 Class for representing physical quantities and constants. A physical quantity 204 has a unit and a value, and optionally a precision and/or a name. A number of 205 physical constants and standard quantities can be obtained as PhysQty objects 206 through static methods. 182 207 208 \sa SOPHYA::Units 209 183 210 \code 184 // Create .... 211 cout << " k_Boltzmann: " << PhysQty::k() << endl; 212 cout << " m_e: " << PhysQty::electron_mass() << endl; 213 // Conversion of a quantity to a different unit 214 PhysQty aj(Units::joule(), 25.); 215 PhysQty aev=aj.ConvertTo(Units::electronvolt().giga()); 216 cout << " A : " << aj << " -> " << aev << endl; 185 217 \endcode 186 218 */ … … 191 223 192 224 /* --Methode-- */ 225 //! Default constructor: zero valued dimensionless quantity 193 226 PhysQty::PhysQty() 194 227 : unit_(), val_(0.), prec_(0.) … … 197 230 198 231 /* --Methode-- */ 232 /*! 233 \brief standard constructor 234 The object is constructed through the specification of the unit \b u, the value \b val, 235 and optional relative precision \b prec (=delta val/val) and an optional name. 236 */ 199 237 PhysQty::PhysQty(Units const & u, r_8 val, r_8 prec, const char* nom) 200 238 : unit_(u), val_(val), prec_(prec), name_((nom==NULL)?"":nom) … … 203 241 204 242 /* --Methode-- */ 243 //! Copy constructor 205 244 PhysQty::PhysQty(PhysQty const & qty) 206 245 : unit_(qty.unit_), val_(qty.val_), prec_(qty.prec_), name_(qty.name_) -
trunk/SophyaLib/BaseTools/sunitpcst.h
r4056 r4062 32 32 33 33 public: 34 //! Default constructor - creates a dimensionless object = 1 34 35 Units(); 36 //! Copy constructor 35 37 Units(Units const& un); 38 //! Base constructor 36 39 Units(const char* nom, const char* snom, int m, int kg, int s, r_8 val=1., int A=0, int K=0, int mol=0, int cd=0); 40 //! Constructor from an existing unit, but with a scaling factor and new name 41 Units(Units const& un, r_8 scale, const char* nom, const char* snom); 42 37 43 virtual ~Units(); 38 44 … … 88 94 89 95 // Les unites usuelles - Voir definition et convention sur 96 // http://www.bipm.org/fr/si/ et http://physics.nist.gov/cuu/Units/ 90 97 inline static Units meter() 91 98 { return Units("meter","m",1,0,0); } … … 153 160 inline static Units radian() 154 161 { return Units("radian","rad",0,0,0,1); } 162 inline static Units degree() 163 { return Units("degree","deg",0,0,0,M_PI/180.); } 155 164 inline static Units steradian() 156 165 { return Units("steradian","sr",0,0,0,1); } … … 219 228 //! Return the physical quantity value in SI units 220 229 inline r_8 SIValue() const { return val_*unit_.SIValue(); } 230 //! Return the associated unit 221 231 inline Units getUnit() {return unit_; } 232 //! Return the associated value 222 233 inline r_8 Value() const { return val_; } 234 //! Change the value of the physical quantity 223 235 inline void setValue(r_8 val) { val_=val; } 236 //! Return the relative precision 224 237 inline r_8 RelativePrecision() const { return prec_; } 238 //! Change the relative precision 225 239 inline void setRelativePrecision(r_8 prec) { prec_=prec; } 240 //! Return the absolute precision 226 241 inline r_8 AbsolutePrecision() const { return prec_*val_; } 227 //! return the unit name242 //! Return the associoated name 228 243 inline string const& Name() const { return name_; } 229 244 -
trunk/SophyaLib/BaseTools/sversion.h
r4056 r4062 3 3 4 4 #define SOPHYA_VERSION 2.2 5 #define SOPHYA_REVISION 225 #define SOPHYA_REVISION 30 6 6 #define SOPHYA_TAG "V_Avr2012" 7 7
Note: See TracChangeset
for help on using the changeset viewer.