Unicode polynomial equation: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Phix}}: syntax coloured, made p2js compatible) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 60:
=={{header|Go}}==
Although this program provides full support for Unicode vulgar fractions, note that there is no guarantee that they (or arithmetic on them) will successfully 'round trip' due to floating point arithmetic being used in the underlying calculations and some of them being recurring rather than exact decimals in any case.
<
import (
Line 316:
printEquation(coefs)
}
}</
{{out}}
Line 371:
=={{header|Julia}}==
The task allows the "polynomials" to be parsed to have negative exponents. This makes them <em>Laurent</em> polynomials, not ordinary polynomials.
<
struct LaurentPolynomial{T}
Line 505:
println(lpad(s, 48), " => ", topoly(s, 'x'))
end
</
<pre>
1x⁵ - 2x⁴ + 42x³ + 0x² + 40x + 1 => x⁵ - 2x⁴ + 42x³ + 40x + 1
Line 524:
=={{header|Nim}}==
{{trans|Go}}
<
from unicode import toRunes
Line 675:
if c != 0: coefs[p] = coefs.getOrDefault(p) + c
printEquation(coefs)</
{{out}}
Line 728:
=={{header|Phix}}==
To simplify this task I first created a test file (save as utf8, Unicode_polynomial_equation.e):
<!--<
<span style="color: #008080;">constant</span> <span style="color: #000000;">raw_text</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"""
-0.00x⁺¹⁰ + 1.0·x ** 5 + -2e0x^4 + +0,042.00 × x ⁺³ + +.0x² + 20.000 000 000x¹ - -1x⁺⁰ + .0x⁻¹ + 20.x¹
Line 773:
<span style="color: #008080;">return</span> <span style="color: #7060A8;">split</span><span style="color: #0000FF;">(</span><span style="color: #000000;">raw_text</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<!--</
Explanation: <br>
On finding a line beginning with "==> ", parse the previous line and check that the output matches the rest of the line.<br>
Line 790:
bytes happen to be less than 255, which would not necessarily be valid utf8/32.
<!--<
<span style="color: #000080;font-style:italic;">-- demo\rosetta\Unicode_polynomial_equation.exw</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">uni_frac</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">WINDOWS</span> <span style="color: #000080;font-style:italic;">-- if true output unicode superscripts and vulgar fractions</span>
Line 1,132:
<span style="color: #0000FF;">?</span><span style="color: #008000;">"done"</span>
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">wait_key</span><span style="color: #0000FF;">()</span>
<!--</
{{out}}
uni_frac = false (ie windows)
Line 1,180:
{{trans|Go}}
{{libheader|Wren-pattern}}
<
var powers = [
Line 1,396:
}
printEquation.call(coefs)
}</
{{out}}
|