Задача: Косинус
Исходник: Табличный косинус, язык: C++ [code #548, hits: 9615]
автор: - [добавлен: 19.12.2007]
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. static const float sin_tab[] = {
  12. 0.000000, 0.012272, 0.024541, 0.036807,
  13. 0.049068, 0.061321, 0.073565, 0.085797,
  14. 0.098017, 0.110222, 0.122411, 0.134581,
  15. 0.146730, 0.158858, 0.170962, 0.183040,
  16. 0.195090, 0.207111, 0.219101, 0.231058,
  17. 0.242980, 0.254866, 0.266713, 0.278520,
  18. 0.290285, 0.302006, 0.313682, 0.325310,
  19. 0.336890, 0.348419, 0.359895, 0.371317,
  20. 0.382683, 0.393992, 0.405241, 0.416430,
  21. 0.427555, 0.438616, 0.449611, 0.460539,
  22. 0.471397, 0.482184, 0.492898, 0.503538,
  23. 0.514103, 0.524590, 0.534998, 0.545325,
  24. 0.555570, 0.565732, 0.575808, 0.585798,
  25. 0.595699, 0.605511, 0.615232, 0.624860,
  26. 0.634393, 0.643832, 0.653173, 0.662416,
  27. 0.671559, 0.680601, 0.689541, 0.698376,
  28. 0.707107, 0.715731, 0.724247, 0.732654,
  29. 0.740951, 0.749136, 0.757209, 0.765167,
  30. 0.773010, 0.780737, 0.788346, 0.795837,
  31. 0.803208, 0.810457, 0.817585, 0.824589,
  32. 0.831470, 0.838225, 0.844854, 0.851355,
  33. 0.857729, 0.863973, 0.870087, 0.876070,
  34. 0.881921, 0.887640, 0.893224, 0.898674,
  35. 0.903989, 0.909168, 0.914210, 0.919114,
  36. 0.923880, 0.928506, 0.932993, 0.937339,
  37. 0.941544, 0.945607, 0.949528, 0.953306,
  38. 0.956940, 0.960431, 0.963776, 0.966976,
  39. 0.970031, 0.972940, 0.975702, 0.978317,
  40. 0.980785, 0.983105, 0.985278, 0.987301,
  41. 0.989177, 0.990903, 0.992480, 0.993907,
  42. 0.995185, 0.996313, 0.997290, 0.998118,
  43. 0.998795, 0.999322, 0.999699, 0.999925
  44. };
  45.  
  46. static const float PITWO = (3.14159265*2);
  47.  
  48. float fgCos(float x) {
  49. const float percent = x/PITWO;
  50. const long idx_untrimmed = (percent+200)*128;
  51. const int idx = idx_untrimmed % 128;
  52. if (idx < (1*128/4))
  53. return sin_tab[(1*128/4) - idx];
  54. else if (idx < (2*128/4))
  55. return -sin_tab[idx - (1*128/4)];
  56. else if (idx < (3*128/4))
  57. return -sin_tab[(3*128/4) - idx];
  58. else
  59. return sin_tab[idx - (3*128/4)];
  60. }
Источник: http://rsdn.ru/forum/Message.aspx?mid=2129883&only=1

+добавить реализацию