Advertisement
7134956

Untitled

Nov 22nd, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. float hum_to_float(const char *s) {
  2. // This function stolen from either Rolf Neugebauer or Andrew Tolmach.
  3. // Probably Rolf.
  4. float a = 0.0f;
  5. int e = 0;
  6. int c;
  7. float sign = 1;
  8.  
  9. c = *s++;
  10.  
  11. if(c == '-') {
  12. sign = -1;
  13. c = *s++;
  14. }
  15.  
  16. while(c != '\0' && isdigit(c)) {
  17. a = a * 10.0f + (c - '0');
  18. c = *s++;
  19. }
  20.  
  21. if(c == '.') {
  22. while((c = *s++) != '\0' && isdigit(c)) {
  23. a = a * 10.0f + (c - '0');
  24. e = e - 1;
  25. }
  26. }
  27.  
  28. if(c <= 'z' && c >= 'E') {
  29. for(int i = 0; c != '\0'; i++) {
  30. if(c == prefix[i]){
  31. a *= prefix_xf[i];
  32. break;
  33. }
  34. }
  35. }
  36.  
  37. while(e > 0) {
  38. a *= 10.0f;
  39. e--;
  40. }
  41.  
  42. while(e < 0) {
  43. a *= 0.1f;
  44. e++;
  45. }
  46.  
  47. return a * sign;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement