Added $$get_rounding_mode and $$set_rounding_mode builtins. (#655)

This commit is contained in:
Dmitry Atamanov
2022-11-14 17:07:32 +05:00
committed by GitHub
parent 49eacb8824
commit 5ff726d8d1
8 changed files with 105 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
import std::io;
import std::math;
fn void main()
{
io::printfln("Current rounding mode: %s", $$get_rounding_mode());
float f1 = 11.5;
float f2 = -11.5;
foreach (int mode : RoundingMode.values)
{
$$set_rounding_mode(mode);
io::printfln("Rounding mode: %s", $$get_rounding_mode());
io::printfln(" ceil(%s) == %s", f1, math::ceil(f1));
io::printfln(" ceil(%s) == %s", f2, math::ceil(f2));
io::printfln(" floor(%s) == %s", f1, math::floor(f1));
io::printfln(" floor(%s) == %s", f2, math::floor(f2));
io::printfln(" nearbyint(%s) == %s", f1, math::nearbyint(f1));
io::printfln(" nearbyint(%s) == %s", f2, math::nearbyint(f2));
io::printfln(" rint(%s) == %s", f1, math::rint(f1));
io::printfln(" rint(%s) == %s", f2, math::rint(f2));
io::printfln(" round(%s) == %s", f1, math::round(f1));
io::printfln(" round(%s) == %s", f2, math::round(f2));
io::printfln(" roundeven(%s) == %s", f1, math::roundeven(f1));
io::printfln(" roundeven(%s) == %s", f2, math::roundeven(f2));
io::printfln(" trunc(%s) == %s", f1, math::trunc(f1));
io::printfln(" trunc(%s) == %s", f2, math::trunc(f2));
}
}