packages feed

ychr-0.1.0.0: test/golden/int_float_conversion/int_float_conversion.chr

:- module(int_float_conversion, [t/2, type(tags/0)]).
:- use_module(prelude).
:- chr_constraint t/2.
:- chr_type tags ---> i2f_zero ; i2f_pos ; i2f_neg ; i2f_big ; f2i_pos ; f2i_neg ; f2i_pos_zero ; f2i_whole ; rt_int ; rt_float.

t(i2f_zero, R)    <=> R is int_to_float(0).
t(i2f_pos, R)     <=> R is int_to_float(42).
t(i2f_neg, R)     <=> R is int_to_float(-7).
t(i2f_big, R)     <=> R is int_to_float(1000000).

t(f2i_pos, R)     <=> R is float_to_int(3.7).
t(f2i_neg, R)     <=> R is float_to_int(-3.7).
t(f2i_pos_zero, R)<=> R is float_to_int(0.0).
t(f2i_whole, R)   <=> R is float_to_int(5.0).

% Round-trip identity for whole-valued ints.
t(rt_int, R)      <=> R is float_to_int(int_to_float(123)).
t(rt_float, R)    <=> R is int_to_float(float_to_int(7.0)).