Determine if a string is numeric: Difference between revisions

m
(Updated D entry)
Line 157:
To check whether a string is a number, a fraction or an integer, use the patterns <code>#</code>, <code>/</code> and <code>~/#</code> ("not a fraction and yet a number"). In the pattern matching examples below (which can be typed in at the Bracmat prompt) <code>F</code> denotes 'failure' and <code>S</code> denotes 'success'.
 
<lang bracmat>43257349578692:/
F
 
Line 169:
S</lang>
Bracmat doesn't do floating point computations (historical reason: the Acorn Risc Machine a.k.a. ARM processor in the Archimedes computer did not have an FPU), but the pattern <code>~/# (|"." (|? 0|`) (|~/#:>0)) (|(E|e) ~/#)</code> recognises string representations of floating point numbers.
<lang bracmat>@("1.000-4E-10":~/# (|"." (|? 0|`) (|~/#:>0)) (|(E|e) ~/#))
F
 
Line 200:
 
To do computations with such "floating point strings" you would have to convert such strings to fractional representations first.
<lang bracmat>(float2fraction=
integerPart decimalPart d1 dn exp sign
. @( !arg
Line 237:
</lang>
Output:
<langpre>6/5
51/50
101/100
Line 247:
-1001/10000
-1/10
0</langpre>
 
=={{header|C}}==
Returns true (non-zero) if character-string parameter represents a signed or unsigned floating-point number. Otherwise returns false (zero).
483

edits