56 lines
1.1 KiB

  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. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstring>
  14. #include <cstdio>
  15. #if USE_SDL && defined __APPLE__
  16. # include <SDL_main.h>
  17. #endif
  18. #include "core.h"
  19. using namespace lol;
  20. using namespace std;
  21. #include "remez-matrix.h"
  22. #include "remez-solver.h"
  23. /* The function we want to approximate */
  24. real myfun(real const &y)
  25. {
  26. real k1024 = 1024;
  27. real klog32 = log((real)32);
  28. return (y - k1024) / log2(log(sqrt(y))/klog32);
  29. real x = sqrt(y);
  30. return (sin(x) - x) / (x * y);
  31. }
  32. real myerr(real const &y)
  33. {
  34. return myfun(y);
  35. return real::R_1;
  36. real x = sqrt(y);
  37. return sin(x) / (x * y);
  38. }
  39. int main(int argc, char **argv)
  40. {
  41. RemezSolver<3> solver;
  42. solver.Run((real)(1024.001), (real)(1024 * 1024), myfun, myerr, 40);
  43. return EXIT_SUCCESS;
  44. }