model_common.c 788 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * SPDX-FileCopyrightText: 2018 Vikrant More
  3. * SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. #include <math.h>
  8. #include "mesh/types.h"
  9. #define MINDIFF (2.25e-308)
  10. float bt_mesh_sqrt(float square)
  11. {
  12. float root = 0.0, last = 0.0, diff = 0.0;
  13. root = square / 3.0;
  14. diff = 1;
  15. if (square <= 0) {
  16. return 0;
  17. }
  18. do {
  19. last = root;
  20. root = (root + square / root) / 2.0;
  21. diff = root - last;
  22. } while (diff > MINDIFF || diff < -MINDIFF);
  23. return root;
  24. }
  25. int32_t bt_mesh_ceil(float num)
  26. {
  27. int32_t inum = (int32_t)num;
  28. if (num == (float)inum) {
  29. return inum;
  30. }
  31. return inum + 1;
  32. }
  33. float bt_mesh_log2(float num)
  34. {
  35. return log2f(num);
  36. }