colon.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // File: colon.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 01-Mar-2023 10:44:39
  6. //
  7. // Include Files
  8. #include "colon.h"
  9. #include "rt_nonfinite.h"
  10. #include "coder_array.h"
  11. #include <cmath>
  12. // Function Definitions
  13. //
  14. // Arguments : double d
  15. // double b
  16. // ::coder::array<double, 2U> &y
  17. // Return Type : void
  18. //
  19. namespace coder {
  20. void eml_float_colon(double d, double b, ::coder::array<double, 2U> &y)
  21. {
  22. double apnd;
  23. double cdiff;
  24. double ndbl;
  25. int n;
  26. ndbl = std::floor(b / d + 0.5);
  27. apnd = ndbl * d;
  28. if (d > 0.0) {
  29. cdiff = apnd - b;
  30. } else {
  31. cdiff = b - apnd;
  32. }
  33. if (std::abs(cdiff) < 4.4408920985006262E-16 * std::abs(b)) {
  34. ndbl++;
  35. apnd = b;
  36. } else if (cdiff > 0.0) {
  37. apnd = (ndbl - 1.0) * d;
  38. } else {
  39. ndbl++;
  40. }
  41. if (ndbl >= 0.0) {
  42. n = static_cast<int>(ndbl);
  43. } else {
  44. n = 0;
  45. }
  46. y.set_size(1, n);
  47. if (n > 0) {
  48. y[0] = 0.0;
  49. if (n > 1) {
  50. int nm1d2;
  51. y[n - 1] = apnd;
  52. nm1d2 = (n - 1) / 2;
  53. for (int k{0}; k <= nm1d2 - 2; k++) {
  54. ndbl = (static_cast<double>(k) + 1.0) * d;
  55. y[k + 1] = ndbl;
  56. y[(n - k) - 2] = apnd - ndbl;
  57. }
  58. if (nm1d2 << 1 == n - 1) {
  59. y[nm1d2] = apnd / 2.0;
  60. } else {
  61. ndbl = static_cast<double>(nm1d2) * d;
  62. y[nm1d2] = ndbl;
  63. y[nm1d2 + 1] = apnd - ndbl;
  64. }
  65. }
  66. }
  67. }
  68. } // namespace coder
  69. //
  70. // File trailer for colon.cpp
  71. //
  72. // [EOF]
  73. //