00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "CeylanMathsBasic.h"
00028
00029 #include "CeylanOperators.h"
00030
00031
00032
00033 #ifdef CEYLAN_USES_CONFIG_H
00034 #include "CeylanConfig.h"
00035 #endif // CEYLAN_USES_CONFIG_H
00036
00037
00038 #if CEYLAN_ARCH_NINTENDO_DS
00039 #include "CeylanConfigForNintendoDS.h"
00040 #endif // CEYLAN_ARCH_NINTENDO_DS
00041
00042
00043 extern "C"
00044 {
00045
00046 #ifdef CEYLAN_USES_MATH_H
00047 #include <math.h>
00048 #endif // CEYLAN_USES_MATH_H
00049
00050 }
00051
00052
00053 #include <cstdlib>
00054 #include <cmath>
00055
00056
00057 using std::string ;
00058
00059 using namespace Ceylan::Maths ;
00060
00061
00062
00063 MathsException::MathsException( const std::string & message ) :
00064 Ceylan::Exception( "Maths exception: " + message )
00065 {
00066
00067 }
00068
00069
00070
00071 MathsException::~MathsException() throw()
00072 {
00073
00074 }
00075
00076
00077
00078
00079
00080
00081 const Ceylan::LongFloat Ceylan::Maths::E =
00082 2.7182818284590452353602874713526625L ;
00083
00084
00085 const Ceylan::LongFloat Ceylan::Maths::Log2E =
00086 1.4426950408889634073599246810018922L ;
00087
00088
00089 const Ceylan::LongFloat Ceylan::Maths::Log10E =
00090 0.4342944819032518276511289189166051L ;
00091
00092
00093 const Ceylan::LongFloat Ceylan::Maths::LogE2 =
00094 0.6931471805599453094172321214581766L ;
00095
00096
00097 const Ceylan::LongFloat Ceylan::Maths::LogE10 =
00098 2.3025850929940456840179914546843642L ;
00099
00100
00101 const Ceylan::LongFloat Ceylan::Maths::Pi =
00102 3.1415926535897932384626433832795029L ;
00103
00104
00105 const Ceylan::LongFloat Ceylan::Maths::Pi_div_2 =
00106 1.5707963267948966192313216916397514L ;
00107
00108
00109 const Ceylan::LongFloat Ceylan::Maths::Pi_div_4 =
00110 0.7853981633974483096156608458198757L ;
00111
00112
00113 const Ceylan::LongFloat Ceylan::Maths::One_div_Pi =
00114 0.3183098861837906715377675267450287L ;
00115
00116
00117 const Ceylan::LongFloat Ceylan::Maths::Two_div_Pi =
00118 0.6366197723675813430755350534900574L ;
00119
00120
00121 const Ceylan::LongFloat Ceylan::Maths::Two_div_sqrt_Pi =
00122 1.1283791670955125738961589031215452L ;
00123
00124
00125 const Ceylan::LongFloat Ceylan::Maths::Sqrt_2 =
00126 1.4142135623730950488016887242096981L ;
00127
00128
00129 const Ceylan::LongFloat Ceylan::Maths::One_div_sqrt_2 =
00130 0.7071067811865475244008443621048490L ;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 const Ceylan::LongFloat Ceylan::Maths::EpsilonFloat32 = 2.0e-7 ;
00144
00145 const Ceylan::LongFloat Ceylan::Maths::EpsilonFloat64 = 1.0e-9 ;
00146
00147 const Ceylan::LongFloat Ceylan::Maths::EpsilonLongFloat = 1.0e-11 ;
00148
00149 const Ceylan::LongFloat Ceylan::Maths::Epsilon = EpsilonFloat32 ;
00150
00151
00152
00153
00154
00155
00156
00157
00158 bool Ceylan::Maths::IsNull( Ceylan::Float32 x )
00159 {
00160
00161 return Abs( x ) < EpsilonFloat32 ;
00162
00163 }
00164
00165
00166
00167 bool Ceylan::Maths::IsNull( Ceylan::Float32 x, Ceylan::Float32 epsilon )
00168 {
00169
00170 return Abs( x ) < epsilon ;
00171
00172 }
00173
00174
00175
00176
00177 bool Ceylan::Maths::IsNull( Ceylan::Float64 x )
00178 {
00179
00180 return Abs( x ) < EpsilonFloat64 ;
00181
00182 }
00183
00184
00185
00186 bool Ceylan::Maths::IsNull( Ceylan::Float64 x, Ceylan::Float64 epsilon )
00187 {
00188
00189 return Abs( x ) < epsilon ;
00190
00191 }
00192
00193
00194
00195 bool Ceylan::Maths::IsNull( Ceylan::LongFloat x )
00196 {
00197
00198 return Abs( x ) < EpsilonLongFloat ;
00199
00200 }
00201
00202
00203
00204 bool Ceylan::Maths::IsNull( Ceylan::LongFloat x, Ceylan::LongFloat epsilon )
00205 {
00206
00207 return Abs( x ) < epsilon ;
00208
00209 }
00210
00211
00212
00213
00214
00215
00216
00217 bool Ceylan::Maths::AreEqual( Ceylan::Float32 x, Ceylan::Float32 y )
00218 {
00219
00220 return Abs( x - y ) < EpsilonFloat32 ;
00221
00222 }
00223
00224
00225
00226 bool Ceylan::Maths::AreEqual( Ceylan::Float32 x, Ceylan::Float32 y,
00227 Ceylan::Float32 epsilon )
00228 {
00229
00230 return Abs( x - y ) < epsilon ;
00231
00232 }
00233
00234
00235
00236 bool Ceylan::Maths::AreEqual( Ceylan::Float64 x, Ceylan::Float64 y )
00237 {
00238
00239 return Abs( x - y ) < EpsilonFloat64 ;
00240
00241 }
00242
00243
00244
00245 bool Ceylan::Maths::AreEqual( Ceylan::Float64 x, Ceylan::Float64 y,
00246 Ceylan::Float64 epsilon )
00247 {
00248
00249 return Abs( x - y ) < epsilon ;
00250
00251 }
00252
00253
00254
00255 bool Ceylan::Maths::AreExactlyEqual( Ceylan::Float64 x, Ceylan::Float64 y )
00256 {
00257
00258
00259
00260 return Abs( x - y )< ( EpsilonLongFloat / 100 ) ;
00261
00262
00263 }
00264
00265
00266
00267 bool Ceylan::Maths::AreEqual( Ceylan::LongFloat x, Ceylan::LongFloat y )
00268 {
00269
00270 return Abs( x - y ) < EpsilonLongFloat ;
00271
00272 }
00273
00274
00275
00276 bool Ceylan::Maths::AreEqual( Ceylan::LongFloat x, Ceylan::LongFloat y,
00277 Ceylan::LongFloat epsilon )
00278 {
00279
00280 return Abs( x - y ) < epsilon ;
00281
00282 }
00283
00284
00285
00286
00287 Ceylan::Float32 Ceylan::Maths::Floor( Ceylan::Float32 x )
00288 {
00289
00290 #ifdef CEYLAN_USES_FLOORF
00291
00292 return ::floorf( x ) ;
00293
00294 #else // CEYLAN_USES_FLOORF
00295
00296 #ifdef CEYLAN_USES_FLOORF
00297
00298
00299 return ::floorf( x ) ;
00300
00301 #else // CEYLAN_USES_FLOORF
00302
00303
00304 return ::floor( x ) ;
00305
00306 #endif // CEYLAN_USES_FLOORF
00307
00308 #endif // CEYLAN_USES_FLOORF
00309
00310 }
00311
00312
00313
00314 Ceylan::Float64 Ceylan::Maths::Floor( Ceylan::Float64 x )
00315 {
00316
00317 return ::floor( x ) ;
00318
00319 }
00320
00321
00322
00323 Ceylan::LongFloat Ceylan::Maths::Floor( Ceylan::LongFloat x )
00324 {
00325
00326 return ::floor( x ) ;
00327
00328 }
00329
00330
00331
00332 Ceylan::Float32 Ceylan::Maths::Ceil( Ceylan::Float32 x )
00333 {
00334
00335 #ifdef CEYLAN_USES_CEILF
00336
00337 return ::ceilf( x ) ;
00338
00339 #else // CEYLAN_USES_CEILF
00340
00341 return ::ceil( x ) ;
00342
00343 #endif // CEYLAN_USES_CEILF
00344
00345 }
00346
00347
00348
00349 Ceylan::Float64 Ceylan::Maths::Ceil( Ceylan::Float64 x )
00350 {
00351
00352 return ::ceil( x ) ;
00353
00354 }
00355
00356
00357
00358 Ceylan::LongFloat Ceylan::Maths::Ceil( Ceylan::LongFloat x )
00359 {
00360
00361 return ::ceil( x ) ;
00362
00363 }
00364
00365
00366
00367
00368
00369
00370
00371 Ceylan::Float32 Ceylan::Maths::Round( Ceylan::Float32 x )
00372 {
00373
00374 #ifdef CEYLAN_USES_ROUNDF
00375
00376 return ::roundf( x ) ;
00377
00378 #else // CEYLAN_USES_ROUNDF
00379
00380 #ifdef CEYLAN_USES_FLOORF
00381
00382
00383 return ::floorf( x ) ;
00384
00385 #else // CEYLAN_USES_FLOORF
00386
00387
00388 return ::floor( x ) ;
00389
00390 #endif // CEYLAN_USES_FLOORF
00391
00392 #endif // CEYLAN_USES_ROUNDF
00393
00394 }
00395
00396
00397
00398 Ceylan::Float32 Ceylan::Maths::Round( Ceylan::Float32 x,
00399 Ceylan::Uint8 precision )
00400 {
00401
00402 Ceylan::Float64 offset =::pow( static_cast<Ceylan::Float64>( 10 ),
00403 precision ) ;
00404
00405 return static_cast<Ceylan::Float32>( Round( offset * x ) / offset ) ;
00406
00407 }
00408
00409
00410
00411 Ceylan::Float64 Ceylan::Maths::Round( Ceylan::Float64 x )
00412 {
00413
00414 #ifdef CEYLAN_USES_ROUND
00415
00416 return ::round( x ) ;
00417
00418 #else // CEYLAN_USES_ROUND
00419
00420 #ifdef CEYLAN_USES_FLOORF
00421
00422
00423 return ::floorf( x ) ;
00424
00425 #else // CEYLAN_USES_FLOORF
00426
00427
00428 return ::floor( x ) ;
00429
00430 #endif // CEYLAN_USES_FLOORF
00431
00432 #endif // CEYLAN_USES_ROUND
00433
00434 }
00435
00436
00437
00438 Ceylan::Float64 Ceylan::Maths::Round( Ceylan::Float64 x,
00439 Ceylan::Uint8 precision )
00440 {
00441
00442 Ceylan::Float64 offset =::pow( static_cast<Ceylan::Float64>( 10 ),
00443 precision ) ;
00444
00445 return Round( offset * x ) / offset ;
00446
00447 }
00448
00449
00450
00451 Ceylan::LongFloat Ceylan::Maths::Round( Ceylan::LongFloat x )
00452 {
00453
00454 #ifdef CEYLAN_USES_ROUND
00455
00456 return ::round( x ) ;
00457
00458 #else // CEYLAN_USES_ROUND
00459
00460 #ifdef CEYLAN_USES_FLOORF
00461
00462
00463 return ::floorf( x ) ;
00464
00465 #else // CEYLAN_USES_FLOORF
00466
00467
00468 return ::floor( x ) ;
00469
00470 #endif // CEYLAN_USES_FLOORF
00471
00472 #endif // CEYLAN_USES_ROUND
00473
00474 }
00475
00476
00477
00478 Ceylan::LongFloat Ceylan::Maths::Round( Ceylan::LongFloat x,
00479 Ceylan::Uint8 precision )
00480 {
00481
00482 Ceylan::LongFloat offset =::pow( static_cast<Ceylan::Float64>( 10 ),
00483 precision ) ;
00484
00485 return static_cast<Ceylan::LongFloat>( Round( offset * x ) / offset ) ;
00486
00487 }
00488
00489
00490
00491 Ceylan::Sint8 Ceylan::Maths::Abs( Ceylan::Sint8 x )
00492 {
00493
00494 return ( x > 0 ) ? x : -x ;
00495
00496 }
00497
00498
00499
00500 Ceylan::Sint16 Ceylan::Maths::Abs( Ceylan::Sint16 x )
00501 {
00502
00503 return ( x > 0 ) ? x : -x ;
00504
00505 }
00506
00507
00508
00509 Ceylan::Sint32 Ceylan::Maths::Abs( Ceylan::Sint32 x )
00510 {
00511
00512 return ::abs( x ) ;
00513
00514 }
00515
00516
00517
00518 Ceylan::SignedLongInteger Ceylan::Maths::Abs( Ceylan::SignedLongInteger x )
00519 {
00520
00521 return ::labs( x ) ;
00522
00523 }
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 Ceylan::Float32 Ceylan::Maths::Abs( Ceylan::Float32 x )
00540 {
00541
00542 #ifdef CEYLAN_USES_FABSF
00543
00544 return ::fabsf( x ) ;
00545
00546 #else // CEYLAN_USES_FABSF
00547
00548 return ::fabs( x ) ;
00549
00550 #endif // CEYLAN_USES_FABSF
00551
00552 }
00553
00554
00555
00556 Ceylan::Float64 Ceylan::Maths::Abs( Ceylan::Float64 x )
00557 {
00558
00559 return ::fabs( x ) ;
00560
00561 }
00562
00563
00564
00565 Ceylan::LongFloat Ceylan::Maths::Abs( Ceylan::LongFloat x )
00566 {
00567
00568 return ::fabs( x ) ;
00569
00570 }
00571
00572
00573
00574
00575 Ceylan::Sint8 Ceylan::Maths::Min( Ceylan::Sint8 x, Ceylan::Sint8 y )
00576 {
00577
00578 return ( x < y ) ? x : y ;
00579
00580 }
00581
00582
00583
00584 Ceylan::Uint8 Ceylan::Maths::Min( Ceylan::Uint8 x, Ceylan::Uint8 y )
00585 {
00586
00587 return ( x < y ) ? x : y ;
00588
00589 }
00590
00591
00592
00593 Ceylan::Sint16 Ceylan::Maths::Min( Ceylan::Sint16 x, Ceylan::Sint16 y )
00594 {
00595
00596 return ( x < y ) ? x : y ;
00597
00598 }
00599
00600
00601
00602 Ceylan::Uint16 Ceylan::Maths::Min( Ceylan::Uint16 x, Ceylan::Uint16 y )
00603 {
00604
00605 return ( x < y ) ? x : y ;
00606
00607 }
00608
00609
00610
00611 Ceylan::Sint32 Ceylan::Maths::Min( Ceylan::Sint32 x, Ceylan::Sint32 y )
00612 {
00613
00614 return ( x < y ) ? x : y ;
00615
00616 }
00617
00618
00619
00620 Ceylan::Uint32 Ceylan::Maths::Min( Ceylan::Uint32 x, Ceylan::Uint32 y )
00621 {
00622
00623 return ( x < y ) ? x : y ;
00624
00625 }
00626
00627
00628
00629 Ceylan::SignedLongInteger Ceylan::Maths::Min( Ceylan::SignedLongInteger x,
00630 Ceylan::SignedLongInteger y )
00631 {
00632
00633 return ( x < y ) ? x : y ;
00634
00635 }
00636
00637
00638
00639 Ceylan::UnsignedLongInteger Ceylan::Maths::Min( Ceylan::UnsignedLongInteger x,
00640 Ceylan::UnsignedLongInteger y )
00641 {
00642
00643 return ( x < y ) ? x : y ;
00644
00645 }
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 Ceylan::Float32 Ceylan::Maths::Min( Ceylan::Float32 x, Ceylan::Float32 y )
00663 {
00664
00665 return ( x < y ) ? x : y ;
00666
00667 }
00668
00669
00670
00671 Ceylan::Float64 Ceylan::Maths::Min( Ceylan::Float64 x, Ceylan::Float64 y )
00672 {
00673
00674 return ( x < y ) ? x : y ;
00675
00676 }
00677
00678
00679
00680 Ceylan::LongFloat Ceylan::Maths::Min( Ceylan::LongFloat x, Ceylan::LongFloat y )
00681 {
00682
00683 return ( x < y ) ? x : y ;
00684
00685 }
00686
00687
00688
00689
00690 Ceylan::Sint8 Ceylan::Maths::Max( Ceylan::Sint8 x, Ceylan::Sint8 y )
00691 {
00692
00693 return ( x > y ) ? x : y ;
00694
00695 }
00696
00697
00698
00699 Ceylan::Uint8 Ceylan::Maths::Max( Ceylan::Uint8 x, Ceylan::Uint8 y )
00700 {
00701
00702 return ( x > y ) ? x : y ;
00703
00704 }
00705
00706
00707
00708 Ceylan::Sint16 Ceylan::Maths::Max( Ceylan::Sint16 x, Ceylan::Sint16 y )
00709 {
00710
00711 return ( x > y ) ? x : y ;
00712
00713 }
00714
00715
00716
00717 Ceylan::Uint16 Ceylan::Maths::Max( Ceylan::Uint16 x, Ceylan::Uint16 y )
00718 {
00719
00720 return ( x > y ) ? x : y ;
00721
00722 }
00723
00724
00725
00726 Ceylan::Sint32 Ceylan::Maths::Max( Ceylan::Sint32 x, Ceylan::Sint32 y )
00727 {
00728 return ( x > y ) ? x : y ;
00729 }
00730
00731
00732 Ceylan::Uint32 Ceylan::Maths::Max( Ceylan::Uint32 x, Ceylan::Uint32 y )
00733 {
00734
00735 return ( x > y ) ? x : y ;
00736
00737 }
00738
00739
00740
00741 Ceylan::SignedLongInteger Ceylan::Maths::Max( Ceylan::SignedLongInteger x,
00742 Ceylan::SignedLongInteger y )
00743 {
00744
00745 return ( x > y ) ? x : y ;
00746
00747 }
00748
00749
00750
00751 Ceylan::UnsignedLongInteger Ceylan::Maths::Max( Ceylan::UnsignedLongInteger x,
00752 Ceylan::UnsignedLongInteger y )
00753 {
00754
00755 return ( x > y ) ? x : y ;
00756
00757 }
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772 Ceylan::Float32 Ceylan::Maths::Max( Ceylan::Float32 x, Ceylan::Float32 y )
00773 {
00774
00775 return ( x > y ) ? x : y ;
00776
00777 }
00778
00779
00780
00781 Ceylan::Float64 Ceylan::Maths::Max( Ceylan::Float64 x, Ceylan::Float64 y )
00782 {
00783
00784 return ( x > y ) ? x : y ;
00785
00786 }
00787
00788
00789
00790 Ceylan::LongFloat Ceylan::Maths::Max( Ceylan::LongFloat x, Ceylan::LongFloat y )
00791 {
00792
00793 return ( x > y ) ? x : y ;
00794
00795 }
00796
00797
00798
00799 Ceylan::Float32 Ceylan::Maths::Exp( Ceylan::Float32 x )
00800 {
00801
00802 #ifdef CEYLAN_USES_EXPF
00803
00804 return ::expf( x ) ;
00805
00806 #else // CEYLAN_USES_EXPF
00807
00808 return ::exp( x ) ;
00809
00810 #endif // CEYLAN_USES_EXPF
00811
00812 }
00813
00814
00815
00816 Ceylan::Float64 Ceylan::Maths::Exp( Ceylan::Float64 x )
00817 {
00818
00819 return ::exp( x ) ;
00820
00821 }
00822
00823
00824
00825 Ceylan::LongFloat Ceylan::Maths::Exp( Ceylan::LongFloat x )
00826 {
00827
00828 return ::exp( x ) ;
00829
00830 }
00831
00832
00833
00834 Ceylan::Float32 Ceylan::Maths::Pow( Ceylan::Float32 x, Ceylan::Float32 y )
00835 {
00836
00837 #ifdef CEYLAN_USES_POWF
00838
00839 return ::powf( x, y ) ;
00840
00841 #else // CEYLAN_USES_POWF
00842
00843 return ::pow( x, y ) ;
00844
00845 #endif // CEYLAN_USES_POWF
00846
00847 }
00848
00849
00850
00851 Ceylan::Float64 Ceylan::Maths::Pow( Ceylan::Float64 x, Ceylan::Float64 y )
00852 {
00853
00854 return ::pow( x, y ) ;
00855
00856 }
00857
00858
00859
00860 Ceylan::LongFloat Ceylan::Maths::Pow( Ceylan::LongFloat x, Ceylan::LongFloat y )
00861 {
00862
00863 return ::pow( x, y ) ;
00864
00865 }
00866
00867
00868
00869 Ceylan::Float32 Ceylan::Maths::Pow2( Ceylan::Float32 x )
00870 {
00871
00872 return x * x ;
00873
00874 }
00875
00876
00877
00878 Ceylan::Float64 Ceylan::Maths::Pow2( Ceylan::Float64 x )
00879 {
00880
00881 return x * x ;
00882
00883 }
00884
00885
00886
00887 Ceylan::LongFloat Ceylan::Maths::Pow2( Ceylan::LongFloat x )
00888 {
00889
00890 return x * x ;
00891
00892 }
00893
00894
00895
00896 Ceylan::Float32 Ceylan::Maths::Log( Ceylan::Float32 x )
00897 {
00898
00899 #ifdef CEYLAN_USES_LOGF
00900
00901 return ::logf( x ) ;
00902
00903 #else // CEYLAN_USES_LOGF
00904
00905 return ::log( x ) ;
00906
00907 #endif // CEYLAN_USES_LOGF
00908
00909 }
00910
00911
00912
00913 Ceylan::Float64 Ceylan::Maths::Log( Ceylan::Float64 x )
00914 {
00915
00916 return ::log( x ) ;
00917
00918 }
00919
00920
00921
00922 Ceylan::LongFloat Ceylan::Maths::Log( Ceylan::LongFloat x )
00923 {
00924
00925 return ::log( x ) ;
00926
00927 }
00928
00929
00930
00931 Ceylan::Float32 Ceylan::Maths::Sqrt( Ceylan::Float32 x )
00932 {
00933
00934 if ( x < 0 )
00935 throw MathsException(
00936 "Sqrt( Ceylan::Float32 x ): parameter is negative ("
00937 + Ceylan::toString( x ) + ")." ) ;
00938
00939 #ifdef CEYLAN_USES_SQRTF
00940
00941 return ::sqrtf( x ) ;
00942
00943 #else // CEYLAN_USES_SQRTF
00944
00945 return ::sqrt( x ) ;
00946
00947 #endif // CEYLAN_USES_SQRTF
00948
00949 }
00950
00951
00952
00953 Ceylan::Float64 Ceylan::Maths::Sqrt( Ceylan::Float64 x )
00954 {
00955
00956 if ( x < 0 )
00957 throw MathsException(
00958 "Sqrt( Ceylan::Float64 x ): parameter is negative ("
00959 + Ceylan::toString( x ) + ")." ) ;
00960
00961 return ::sqrt( x ) ;
00962
00963 }
00964
00965
00966
00967 Ceylan::LongFloat Ceylan::Maths::Sqrt( Ceylan::LongFloat x )
00968 {
00969
00970 if ( x < 0 )
00971 throw MathsException(
00972 "Sqrt( Ceylan::LongFloat x ): parameter is negative ("
00973 + Ceylan::toString( x ) + ")." ) ;
00974
00975 return ::sqrt( x ) ;
00976
00977 }
00978
00979
00980
00981
00982
00983
00984
00985 Ceylan::Float32 Ceylan::Maths::Cos( Ceylan::Float32 angle )
00986 {
00987
00988 #if CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
00989
00990 int32 c = COS[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
00991
00992 return f32tofloat( c ) ;
00993
00994 #else // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
00995
00996 #ifdef CEYLAN_USES_COSF
00997
00998 return ::cosf( angle ) ;
00999
01000 #else // CEYLAN_USES_COSF
01001
01002 return ::cos( angle ) ;
01003
01004 #endif // CEYLAN_USES_COSF
01005
01006 #endif // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01007
01008 }
01009
01010
01011
01012 Ceylan::Float64 Ceylan::Maths::Cos( Ceylan::Float64 angle )
01013 {
01014
01015 return ::cos( angle ) ;
01016
01017 }
01018
01019
01020
01021 Ceylan::LongFloat Ceylan::Maths::Cos( Ceylan::LongFloat angle )
01022 {
01023
01024 return ::cos( angle ) ;
01025
01026 }
01027
01028
01029
01030
01031
01032
01033
01034 Ceylan::Float32 Ceylan::Maths::Sin( Ceylan::Float32 angle )
01035 {
01036
01037 #if CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01038
01039 int32 c = SIN[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
01040
01041 return f32tofloat( c ) ;
01042
01043 #else // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01044
01045 #ifdef CEYLAN_USES_SINF
01046
01047 return ::sinf( angle ) ;
01048
01049 #else // CEYLAN_USES_SINF
01050
01051 return ::sin( angle ) ;
01052
01053 #endif // CEYLAN_USES_SINF
01054
01055 #endif // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01056
01057 }
01058
01059
01060
01061 Ceylan::Float64 Ceylan::Maths::Sin( Ceylan::Float64 angle )
01062 {
01063
01064 return ::sin( angle ) ;
01065
01066 }
01067
01068
01069
01070 Ceylan::LongFloat Ceylan::Maths::Sin( Ceylan::LongFloat angle )
01071 {
01072
01073 return ::sin( angle ) ;
01074
01075 }
01076
01077
01078
01079
01080
01081
01082
01083
01084 Ceylan::Float32 Ceylan::Maths::Tan( Ceylan::Float32 angle )
01085 {
01086
01087 #if CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01088
01089 int32 c = TAN[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
01090
01091 return f32tofloat( c ) ;
01092
01093 #else // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01094
01095 #ifdef CEYLAN_USES_SINF
01096
01097 return ::tanf( angle ) ;
01098
01099 #else // CEYLAN_USES_SINF
01100
01101 return ::tan( angle ) ;
01102
01103 #endif // CEYLAN_USES_SINF
01104
01105 #endif // CEYLAN_ARCH_NINTENDO_DS && defined(CEYLAN_RUNS_ON_ARM9)
01106
01107 }
01108
01109
01110
01111 Ceylan::Float64 Ceylan::Maths::Tan( Ceylan::Float64 angle )
01112 {
01113
01114 return ::tan( angle ) ;
01115
01116 }
01117
01118
01119
01120 Ceylan::LongFloat Ceylan::Maths::Tan( Ceylan::LongFloat angle )
01121 {
01122
01123 return ::tan( angle ) ;
01124
01125 }
01126
01127
01128
01129
01130 #if defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
01131
01132
01133
01134
01135
01136 Ceylan::Uint32 Ceylan::Maths::SqrtFixed( Ceylan::Uint32 x )
01137 {
01138
01139 return ::swiSqrt( x ) ;
01140
01141 }
01142
01143
01144 #ifdef CEYLAN_RUNS_ON_ARM9
01145
01146
01147 Ceylan::Sint32 Ceylan::Maths::CosFixed( Ceylan::Sint32 angle )
01148 {
01149
01150 return COS[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
01151
01152 }
01153
01154
01155
01156 Ceylan::Sint32 Ceylan::Maths::SinFixed( Ceylan::Sint32 angle )
01157 {
01158
01159 return SIN[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
01160
01161 }
01162
01163
01164
01165 Ceylan::Sint32 Ceylan::Maths::TanFixed( Ceylan::Sint32 angle )
01166 {
01167
01168 return TAN[(int)((angle * LUT_SIZE) / (2.0*Pi)) & LUT_MASK] ;
01169
01170 }
01171
01172
01173 #endif // CEYLAN_RUNS_ON_ARM9
01174
01175 #endif // defined(CEYLAN_ARCH_NINTENDO_DS) && CEYLAN_ARCH_NINTENDO_DS == 1
01176
01177
01178
01179
01180
01181
01182
01183 AngleInRadians Ceylan::Maths::DegreeToRadian( AngleInDegrees angleInDegrees )
01184 {
01185
01186 return static_cast<AngleInRadians>( angleInDegrees * Pi / 180.0 ) ;
01187
01188 }
01189
01190
01191
01192 Ceylan::Uint16 Ceylan::Maths::NextPowerOfTwo( Ceylan::Uint16 value )
01193 {
01194
01195
01196
01197 Ceylan::Uint16 result = 1 ;
01198
01199
01200 while ( result < value )
01201 result *= 2 ;
01202
01203 return result ;
01204
01205 }
01206
01207
01208
01209 bool Ceylan::Maths::IsAPowerOfTwo( Ceylan::Uint16 value )
01210 {
01211
01212 return ( value == NextPowerOfTwo( value ) ) ;
01213
01214 }
01215
01216
01217
01218 Ceylan::Uint16 Ceylan::Maths::NextMultipleOf( Uint16 multiple, Uint16 value )
01219 {
01220
01221 if ( value % multiple == 0 )
01222 return value ;
01223
01224
01225 return multiple * ( ( value / multiple ) + 1 ) ;
01226
01227 }
01228
01229
01230
01231
01232 Ceylan::Maths::IntToIntFunctor::IntToIntFunctor(
01233 Ceylan::Sint32 creationParameter ) :
01234 Functor(),
01235 _creationParameter( creationParameter )
01236 {
01237
01238 }
01239
01240
01241
01242 Ceylan::Maths::IntToIntFunctor::~IntToIntFunctor() throw()
01243 {
01244
01245 }
01246
01247
01248
01249 const string Ceylan::Maths::IntToIntFunctor::toString(
01250 Ceylan::VerbosityLevels level ) const
01251 {
01252
01253 return "IntToIntFunctor functor" ;
01254
01255 }
01256