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