/* * LIBMATH.C * * Copyright (C) 1993-1997 by Sony Computer Entertainment of America, Inc. * All rights Reserved * ---------------------------------------------------------------------------- * * This file contains math data tables and functions. This file can be * used as is in any other project and can be expanded to provide more * functionalities of a math library. * * This file contains two data tables - Sine and Cosine tables which have * a resolution of 257. This has been d4096 to provide access to the sine * and cosine of an angle which is defined in PlayStation format, i.e. * 4096 is equivalent of 360 degrees. Sine and Cosine functions expect * an angle which can be anywhere between -4096 to any positive value. * The tables have a resolution of 257 to provide an angular value from * 0 to 4096. * ---------------------------------------------------------------------------- */ //#include "libmain.h" #include "libmath.h" /* * Sin/Cosine Tables * ---------------------------------------------------------------------------- */ short SinTable[257] = { 0, 25, 50, 75, 100, 125, 150, 175, 200, 224, 249, 273, 297, 321, 345, 369, 392, 415, 438, 460, 483, 505, 526, 548, 569, 590, 610, 630, 650, 669, 688, 706, 724, 742, 759, 775, 792, 807, 822, 837, 851, 865, 878, 891, 903, 915, 926, 936, 946, 955, 964, 972, 980, 987, 993, 999, 1004, 1009, 1013, 1016, 1019, 1021, 1023, 1024, 1024, 1024, 1023, 1021, 1019, 1016, 1013, 1009, 1004, 999, 993, 987, 980, 972, 964, 955, 946, 936, 926, 915, 903, 891, 878, 865, 851, 837, 822, 807, 792, 775, 759, 742, 724, 706, 688, 669, 650, 630, 610, 590, 569, 548, 526, 505, 483, 460, 438, 415, 392, 369, 345, 321, 297, 273, 249, 224, 200, 175, 150, 125, 100, 75, 50, 25, 0, -24, -49, -74, -99, -124, -149, -174, -199, -223, -248, -272, -296, -320, -344, -368, -391, -414, -437, -459, -482, -504, -525, -547, -568, -589, -609, -629, -649, -668, -687, -705, -723, -741, -758, -774, -791, -806, -821, -836, -850, -864, -877, -890, -902, -914, -925, -935, -945, -954, -963, -971, -979, -986, -992, -998, -1003, -1008, -1012, -1015, -1018, -1020, -1022, -1023, -1023, -1023, -1022, -1020, -1018, -1015, -1012, -1008, -1003, -998, -992, -986, -979, -971, -963, -954, -945, -935, -925, -914, -902, -890, -877, -864, -850, -836, -821, -806, -791, -774, -758, -741, -723, -705, -687, -668, -649, -629, -609, -589, -568, -547, -525, -504, -482, -459, -437, -414, -391, -368, -344, -320, -296, -272, -248, -223, -199, -174, -149, -124, -99, -74, -49, -24, 0, }; short CosTable[257] = { 1024, 1024, 1023, 1021, 1019, 1016, 1013, 1009, 1004, 999, 993, 987, 980, 972, 964, 955, 946, 936, 926, 915, 903, 891, 878, 865, 851, 837, 822, 807, 792, 775, 759, 742, 724, 706, 688, 669, 650, 630, 610, 590, 569, 548, 526, 505, 483, 460, 438, 415, 392, 369, 345, 321, 297, 273, 249, 224, 200, 175, 150, 125, 100, 75, 50, 25, 0, -24, -49, -74, -99, -124, -149, -174, -199, -223, -248, -272, -296, -320, -344, -368, -391, -414, -437, -459, -482, -504, -525, -547, -568, -589, -609, -629, -649, -668, -687, -705, -723, -741, -758, -774, -791, -806, -821, -836, -850, -864, -877, -890, -902, -914, -925, -935, -945, -954, -963, -971, -979, -986, -992, -998, -1003, -1008, -1012, -1015, -1018, -1020, -1022, -1023, -1023, -1023, -1022, -1020, -1018, -1015, -1012, -1008, -1003, -998, -992, -986, -979, -971, -963, -954, -945, -935, -925, -914, -902, -890, -877, -864, -850, -836, -821, -806, -791, -774, -758, -741, -723, -705, -687, -668, -649, -629, -609, -589, -568, -547, -525, -504, -482, -459, -437, -414, -391, -368, -344, -320, -296, -272, -248, -223, -199, -174, -149, -124, -99, -74, -49, -24, 0, 25, 50, 75, 100, 125, 150, 175, 200, 224, 249, 273, 297, 321, 345, 369, 392, 415, 438, 460, 483, 505, 526, 548, 569, 590, 610, 630, 650, 669, 688, 706, 724, 742, 759, 775, 792, 807, 822, 837, 851, 865, 878, 891, 903, 915, 926, 936, 946, 955, 964, 972, 980, 987, 993, 999, 1004, 1009, 1013, 1016, 1019, 1021, 1023, 1024, 1024, }; /* Sine Function */ short MySin(short angle) { return(SinTable[((((angle + 4096) % 4096) + 8) / 16)]); } /* Cosine Function */ short MyCos(short angle) { return(CosTable[((((angle + 4096) % 4096) + 8) / 16)]); } /* * Abs * ---------------------------------------------------------------------------- */ short MySabs(short a) { return((a >= 0) ? a : -a); } int MyAbs(int a) { return((a >= 0) ? a : -a); } long MyLabs(long a) { return((a >= 0) ? a : -a); } /* * End of File * ---------------------------------------------------------------------------- */