approx.spec.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { fasterPow2, fasterExp, fasterLog, fasterLog10, fasterSin, fasterCos, fastAtan, fastAtan2, fasterTan, fasterTanh, fasterCosh, fasterSinh, fastPow2, fastExp, fastLog, fastLog10, fastSinh, fastCosh, fastTanh, fastSin, fastCos, fastTan } from '../../approx';
  7. describe('approx', () => {
  8. it('fastPow2', () => {
  9. expect(fastPow2(4)).toBeCloseTo(Math.pow(2, 4), 2);
  10. });
  11. it('fasterPow2', () => {
  12. expect(fasterPow2(4)).toBeCloseTo(Math.pow(2, 4), 0);
  13. });
  14. it('fastExp', () => {
  15. expect(fastExp(4)).toBeCloseTo(Math.exp(4), 2);
  16. });
  17. it('fasterExp', () => {
  18. expect(fasterExp(4)).toBeCloseTo(Math.exp(4), 0);
  19. });
  20. it('fastLog', () => {
  21. expect(fastLog(12)).toBeCloseTo(Math.log(12), 2);
  22. });
  23. it('fasterLog', () => {
  24. expect(fasterLog(12)).toBeCloseTo(Math.log(12), 1);
  25. });
  26. it('fastLog10', () => {
  27. expect(fastLog10(42)).toBeCloseTo(Math.log10(42), 2);
  28. });
  29. it('fasterLog10', () => {
  30. expect(fasterLog10(42)).toBeCloseTo(Math.log10(42), 1);
  31. });
  32. it('fastSinh', () => {
  33. expect(fastSinh(0.3)).toBeCloseTo(Math.sinh(0.3), 2);
  34. });
  35. it('fasterSinh', () => {
  36. expect(fasterSinh(0.3)).toBeCloseTo(Math.sinh(0.3), 1);
  37. });
  38. it('fastCosh', () => {
  39. expect(fastCosh(0.3)).toBeCloseTo(Math.cosh(0.3), 2);
  40. });
  41. it('fasterCosh', () => {
  42. expect(fasterCosh(0.3)).toBeCloseTo(Math.cosh(0.3), 1);
  43. });
  44. it('fastTanh', () => {
  45. expect(fastTanh(0.3)).toBeCloseTo(Math.tanh(0.3), 2);
  46. });
  47. it('fasterTanh', () => {
  48. expect(fasterTanh(0.3)).toBeCloseTo(Math.tanh(0.3), 1);
  49. });
  50. it('fastSin', () => {
  51. expect(fastSin(0.3)).toBeCloseTo(Math.sin(0.3), 2);
  52. });
  53. it('fasterSin', () => {
  54. expect(fasterSin(0.3)).toBeCloseTo(Math.sin(0.3), 1);
  55. });
  56. it('fastCos', () => {
  57. expect(fastCos(0.3)).toBeCloseTo(Math.cos(0.3), 2);
  58. });
  59. it('fasterCos', () => {
  60. expect(fasterCos(0.3)).toBeCloseTo(Math.cos(0.3), 1);
  61. });
  62. it('fastTan', () => {
  63. expect(fastTan(0.3)).toBeCloseTo(Math.tan(0.3), 2);
  64. });
  65. it('fasterTan', () => {
  66. expect(fasterTan(0.3)).toBeCloseTo(Math.tan(0.3), 1);
  67. });
  68. it('fastAtan', () => {
  69. expect(fastAtan(0.3)).toBeCloseTo(Math.atan(0.3), 2);
  70. });
  71. it('fastAtan2', () => {
  72. expect(fastAtan2(0.1, 0.5)).toBeCloseTo(Math.atan2(0.1, 0.5), 2);
  73. });
  74. });