Increment a numerical string: Difference between revisions

(→‎dt: add)
Tag: Manual revert
 
(5 intermediate revisions by 5 users not shown)
Line 932:
 
=={{header|Bracmat}}==
Numbers are strings. Bracmat supports rational numbers, including integers, using arbitrary-precision arithmetic. Pure imaginary numbers are formed using a factor <code>i</code> (or <code>-i</code>). There is no support for floating point arithmetics. (Historically, because the ARM 2 processor in the Archimedes computer didn't sport an FPU.)
<syntaxhighlight lang="bracmat">(n=35664871829866234762187538073934873121878/6172839450617283945)
&!n+1:?n
Line 939:
35664871829866234762193710913385490405823/6172839450617283945
</syntaxhighlight>
Output
<pre></pre>
 
Bracmat also supports floating point numbers, but only in a sandboxed way. To increment 0.234E0 by 1:
 
<syntaxhighlight lang="bracmat">(new$(UFP,(=(s.val).!val+1)).go)$"0.234e0"</syntaxhighlight>
Output
<pre>1.2340000000000000E+00</pre>
 
<code>UFP</code> is a new (2023) object type that specializes in compiling and executing floating point operations. Bracmat code must be passed when a UFP object is created. This code has a more restricted grammar than Bracmat code in general. The passed code must be the definition of a function that can take one or more scalars or arrays as argument. In the example, this function is <code>(=(s.val).!val+1)</code>. The expression <code>(s.val)</code> says that the function takes a scalar and binds it to the local variable <code>val</code>. In the example, the function is defined, compiled, executed and destroyed in one go. This is not necessary; it is perfectly possible to use the compiled UFP object multiple times before destroying it.
 
=={{header|Brat}}==
Line 1,587 ⟶ 1,597:
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Increment_a_numerical_string}}
 
'''Solution'''
 
[[File:Fōrmulæ - Increment a numerical string 01.png]]
 
[[File:Fōrmulæ - Increment a numerical string 02.png]]
 
=={{header|Gambas}}==
Line 2,276 ⟶ 2,293:
numStr = num2str(str2double(numStr) + 1);
end</syntaxhighlight>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
inc_string(str):=if stringp(str) and numberp(eval_string(str)) then string(eval_string(str)+1)$
"12345"$
inc_string(%);
</syntaxhighlight>
{{out}}
<pre>
"12346"
</pre>
 
=={{header|MAXScript}}==
Line 3,594 ⟶ 3,622:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var ns = "41"
var n = Num.fromString(ns) + 1
var ns2 = "%(n)"
305

edits