1 | // |
---|

2 | // Lol Engine - Sample math program: Chebyshev polynomials |
---|

3 | // |
---|

4 | // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net> |
---|

5 | // This program is free software; you can redistribute it and/or |
---|

6 | // modify it under the terms of the Do What The Fuck You Want To |
---|

7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|

8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|

9 | // |
---|

10 | |
---|

11 | #if defined HAVE_CONFIG_H |
---|

12 | # include "config.h" |
---|

13 | #endif |
---|

14 | |
---|

15 | #include <cstring> |
---|

16 | #include <cstdio> |
---|

17 | |
---|

18 | #include "core.h" |
---|

19 | |
---|

20 | using namespace lol; |
---|

21 | using namespace std; |
---|

22 | |
---|

23 | #include "remez-matrix.h" |
---|

24 | #include "remez-solver.h" |
---|

25 | |
---|

26 | /* The function we want to approximate */ |
---|

27 | static real myfun(real const &x) |
---|

28 | { |
---|

29 | static real const a0 = real::R_1; |
---|

30 | static real const a1 = real(-11184811) >> 26; |
---|

31 | static real const b1 = real(-1) / real(6); |
---|

32 | static real const b2 = real(1) / real(120); |
---|

33 | real y = sqrt(x); |
---|

34 | if (!y) |
---|

35 | return b2; |
---|

36 | return ((sin(y) / y - a0) / x - a1) / x; |
---|

37 | } |
---|

38 | |
---|

39 | static real myerr(real const &x) |
---|

40 | { |
---|

41 | return real::R_1; |
---|

42 | } |
---|

43 | |
---|

44 | int main(int argc, char **argv) |
---|

45 | { |
---|

46 | RemezSolver<3> solver; |
---|

47 | //solver.Run(0, 1, myfun, myfun, 15); |
---|

48 | solver.Run(0, real::R_PI * real::R_PI >> 2, myfun, myfun, 15); |
---|

49 | //solver.Run(-1, 1, myfun, myfun, 15); |
---|

50 | //solver.Run(0, real::R_PI * real::R_PI >> 4, myfun, myfun, 15); |
---|

51 | |
---|

52 | return EXIT_SUCCESS; |
---|

53 | } |
---|

54 | |
---|