Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

noniso.cpp 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. noniso.cpp - replacements for non-ISO functions used by Arduino core
  3. Copyright © 2016 Ivan Grokhotkov
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. Modified August 2016 by Marcelo Aquino <marceloaqno@gmail.org> for MySensors use
  13. */
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #include <math.h>
  20. #include "stdlib_noniso.h"
  21. char* utoa(unsigned value, char* result, int base)
  22. {
  23. if(base < 2 || base > 16) {
  24. *result = 0;
  25. return result;
  26. }
  27. char* out = result;
  28. unsigned quotient = value;
  29. do {
  30. const unsigned tmp = quotient / base;
  31. *out = "0123456789abcdef"[quotient - (tmp * base)];
  32. ++out;
  33. quotient = tmp;
  34. } while(quotient);
  35. reverse(result, out);
  36. *out = 0;
  37. return result;
  38. }
  39. char* itoa(int value, char* result, int base)
  40. {
  41. if(base < 2 || base > 16) {
  42. *result = 0;
  43. return result;
  44. }
  45. char* out = result;
  46. int quotient = abs(value);
  47. do {
  48. const int tmp = quotient / base;
  49. *out = "0123456789abcdef"[quotient - (tmp * base)];
  50. ++out;
  51. quotient = tmp;
  52. } while(quotient);
  53. // Apply negative sign
  54. if(value < 0) {
  55. *out++ = '-';
  56. }
  57. reverse(result, out);
  58. *out = 0;
  59. return result;
  60. }
  61. int atoi(const char* s)
  62. {
  63. return (int) atol(s);
  64. }
  65. long atol(const char* s)
  66. {
  67. char * tmp;
  68. return strtol(s, &tmp, 10);
  69. }
  70. double atof(const char* s)
  71. {
  72. char * tmp;
  73. return strtod(s, &tmp);
  74. }
  75. void reverse(char* begin, char* end)
  76. {
  77. char *is = begin;
  78. char *ie = end - 1;
  79. while(is < ie) {
  80. char tmp = *ie;
  81. *ie = *is;
  82. *is = tmp;
  83. ++is;
  84. --ie;
  85. }
  86. }
  87. char* ltoa(long value, char* result, int base)
  88. {
  89. if(base < 2 || base > 16) {
  90. *result = 0;
  91. return result;
  92. }
  93. char* out = result;
  94. long quotient = abs(value);
  95. do {
  96. const long tmp = quotient / base;
  97. *out = "0123456789abcdef"[quotient - (tmp * base)];
  98. ++out;
  99. quotient = tmp;
  100. } while(quotient);
  101. // Apply negative sign
  102. if(value < 0) {
  103. *out++ = '-';
  104. }
  105. reverse(result, out);
  106. *out = 0;
  107. return result;
  108. }
  109. char* ultoa(unsigned long value, char* result, int base)
  110. {
  111. if(base < 2 || base > 16) {
  112. *result = 0;
  113. return result;
  114. }
  115. char* out = result;
  116. unsigned long quotient = value;
  117. do {
  118. const unsigned long tmp = quotient / base;
  119. *out = "0123456789abcdef"[quotient - (tmp * base)];
  120. ++out;
  121. quotient = tmp;
  122. } while(quotient);
  123. reverse(result, out);
  124. *out = 0;
  125. return result;
  126. }
  127. char* dtostrf (double val, signed char width, unsigned char prec, char *s)
  128. {
  129. sprintf(s,"%*.*f", width, prec, val);
  130. return s;
  131. }