algo.stflow 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. FLOW: toNumber
  2. input: x, options
  3. IF not string
  4. END x
  5. ELSE_IF should skip
  6. END x
  7. ELSE_IF 0
  8. END 0
  9. ELSE_IF hex is supported AND x is hex
  10. END int of x of base 16
  11. ELSE_IF possible e notation
  12. FOLLOW: resolve enotation (x, trimmed x, options)
  13. ELSE
  14. IF match numeric pattern
  15. separate sign, leading zeros, pure number
  16. IF x doesn't starts with "[+-]0."
  17. END number(x)
  18. IF leading zeros are not allowed
  19. IF leading zeros > 1
  20. #00.1
  21. END x
  22. ELSE_IF leading zeros == 1 AND decimal is not adjacent to leading zeros
  23. #06.5
  24. #but not 0.65, .65, 6.0
  25. END x
  26. ELSE_IF str has only zeros
  27. END 0
  28. ELSE
  29. parse x to number
  30. IF parsed x == 0 or -0
  31. END parsed x
  32. ELSE_IF parsed x is eNotation
  33. IF conversion to enotation is allowed
  34. END parsed x
  35. ELSE
  36. END x
  37. ELSE_IF floating number
  38. IF parsed x is 0
  39. END parsed x
  40. ELSE_IF parsed x == number without leading 0s
  41. #0.456. 0.79000
  42. END parsed x
  43. ELSE_IF parsed x is negative AND == parsed x == number without leading 0s
  44. END parsed x
  45. ELSE
  46. END x
  47. ELSE_IF leading 0s are present
  48. IF parsed x == x without leading 0s
  49. END parsed x
  50. ELSE
  51. END x
  52. ELSE
  53. IF parsed x == x (consider sign)
  54. END parsed x
  55. ELSE
  56. END x
  57. ELSE
  58. END x
  59. FLOW: resolve enotation
  60. input: x, trimmed x, options
  61. IF eNotation has not to be evaluated
  62. END x
  63. IF match eNotation pattern
  64. extract sign, eChar, leading zeros
  65. find if eChar adjacent to leading zeros
  66. IF leading zeros > 1 AND eChar adjacent to leading zeros
  67. # 00e, -00e
  68. END x
  69. ELSE_IF exp is `0e`, `0.e`, `-0.e`, `-0e`
  70. END number(x);
  71. ELSE_IF leading zeros are allowed but eChar is not adjacent to leading zeros
  72. # -003e2
  73. remove leading zeros
  74. END number(x)
  75. ELSE
  76. END x
  77. ELSE
  78. END x