IEEE 754?にあるコードの細かい部分を取り上げて、C言語とLLPML?の比較をします。
LLPMLの表記は冗長なため、0.9より式の中置記法をサポートしました。 ⇒ LLPML/簡略化?
C言語
LLPML(簡略版)
LLPML(従来版)
printf("3.14159265 => ");
Float(314159265, -8);
printf("3.14159265 => ");
Float(314159265, -8);
<call name="printf"><string>3.14159265 => </string></call> <call name="Float"><int>314159265</int><int>-8</int></call>
printf("%d-%d-%p\n", sign, e2 + SIGN_DIGIT + EXP_MAX / 2, s & SIGN_MAX);
printf("%d-%d-%p\n", sign, e2 + SIGN_DIGIT + EXP_MAX / 2, s and SIGN_MAX);
<call name="printfln">
<string>%d-%d-%p</string>
<var name="sign" />
<add>
<var name="e2" />
<int name="SIGN_DIGIT" />
<div><int name="EXP_MAX" />2</div>
</add>
<and>
<var name="s" />
<int name="SIGN_MAX" />
</and>
</call>
※簡略版はありません。
void Float(int s, int e10) {
}
<function name="Float"> <arg name="s" /> <arg name="e10" /> </function>
※簡略版はありません。
int sign = 0, e2 = 0, ss;
<var-declare name="sign">0</var-declare> <var-declare name="e2">0</var-declare> <var-declare name="ss" />
if (s == 0) e10 = 0;
<if>
<cond>s == 0</cond>
<block>
e10 = 0;
</block>
</if>
<if>
<cond>
<equal><var name="s" />0</equal>
</cond>
<block>
<let><var name="e10" />0</let>
</block>
</if>
if (s < 0) sign = 1, s = -s;
<if>
<cond>0 > s</cond>
<block>
sign = 1;
s = -s;
</block>
</if>
<if>
<cond>
<less><var name="s" />0</less>
</cond>
<block>
<let><var name="sign" />1</let>
<let>
<var name="s" />
<sub>0<var name="s" /></sub>
</let>
</block>
</if>
if (e10 < 0) {
} else if (e10 > 0) {
}
<if> <cond>0 > e10</cond> <block> </block> <cond>e10 > 0</cond> <block> </block> </if>
<if>
<cond>
<less><var name="e10" />0</less>
</cond>
<block>
</block>
<cond>
<greater><var name="e10" />0</greater>
</cond>
<block>
</block>
</if>
if (ss == 0 || s > INT_MAX / 2);
<if> <cond>ss == 0 || s > INT_MAX / 2</cond> <block> </block> </if>
<if>
<cond>
<or-else>
<equal><var name="ss" />0</equal>
<greater>
<var name="s" />
<div><int name="INT_MAX" />2</div>
</greater>
</or-else>
</cond>
<block>
</block>
</if>
if (s & 1 == 1 && s <= INT_MAX / 10) e10--, s *= 10;
<if>
<cond>s and 1 == 1 andalso INT_MAX / 10 >= s</cond>
<block>
e10--;
s *= 10;
</block>
</if>
<if>
<cond>
<and-also>
<equal>
<and><var name="s" />1</and>
<int>1</int>
</equal>
<less-equal>
<var name="s" />
<div><int name="INT_MAX" />10</div>
</less-equal>
</and-also>
</cond>
<block>
<dec><var name="e10" /></dec>
<var-mul><var name="s" />10</var-mul>
</block>
</if>
while (s % 10 == 0) e10++, s /= 10;
<while>
<cond>s % 10 == 0</cond>
<block>
e10++;
s /= 10;
</block>
</while>
<while>
<cond>
<equal>
<mod><var name="s" />10</mod>
<int>0</int>
</equal>
</cond>
<block>
<inc><var name="e10" /></inc>
<var-div><var name="s" />10</var-div>
</block>
</while>
while (e10 != 0) {
}
<while> <cond>e10 != 0</cond> <block> </block> </while>
<while>
<cond>
<not-equal><var name="e10" />0</not-equal>
</cond>
<block>
</block>
</while>
while (s > 0 && s <= SIGN_MAX) e2--, s *= 2;
<while>
<cond>s > 0 andalso SIGN_MAX >= s</cond>
<block>
e2--;
s *= 2;
</block>
</while>
<while>
<cond>
<and-also>
<greater><var name="s" />0</greater>
<less-equal>
<var name="s" />
<int name="SIGN_MAX" />
</less-equal>
</and-also>
</cond>
<block>
<dec><var name="e2" /></dec>
<var-mul><var name="s" />2</var-mul>
</block>
</while>
while (s > SIGN_MAX * 2 + 1) e2++, s = (s / 2) + (s & 1);
<while>
<cond>s > SIGN_MAX * 2 + 1</cond>
<block>
e2++;
s = (s / 2) + (s and 1);
</block>
</while>
<while>
<cond>
<greater>
<var name="s" />
<add>
<mul><int name="SIGN_MAX" />2</mul>
<int>1</int>
</add>
</greater>
</cond>
<block>
<inc><var name="e2" /></inc>
<let>
<var name="s" />
<add>
<div><var name="s" />2</div>
<and><var name="s" />1</and>
</add>
</let>
</block>
</while>