%{
#define
ATSCODEFORMAT "txt"
//
#if (ATSCODEFORMAT == "txt")
//
#include
"utils/atsdoc/HATS/postiatsatxt.hats"
//
#endif // end of [ATSCCODEFORMAT]
//
val
_thisfilename = atext_strcst"float.cats"
//
val () =
theAtextMap_insert_str("thisfilename", _thisfilename)
//
%}\
\
#atscode_banner_for_C()
#atscode_copyright_GPL_for_C()

#atscode_separator_for_C()

/*
** Source:
** $PATSHOME/prelude/CATS/CODEGEN/float.atxt
** Time of generation: #timestamp()
*/

#atscode_separator_for_C()

/*
#atscode_author("Hongwei Xi")
#atscode_authoremail("hwxi AT cs DOT bu DOT edu")
#atscode_start_time("April, 2012")
*/

#atscode_separator_for_C()

\#ifndef ATSLIB_PRELUDE_CATS_FLOAT
\#define ATSLIB_PRELUDE_CATS_FLOAT

#atscode_separator_for_C()

ATSinline()
atstype_float
atspre_g0int2float_int_float
  (atstype_int x) { return ((atstype_float)x) ; }
// end of [atspre_g0int2float_int_float]

ATSinline()
atstype_double
atspre_g0int2float_int_double
  (atstype_int x) { return ((atstype_double)x) ; }
// end of [atspre_g0int2float_int_double]

ATSinline()
atstype_double
atspre_g0int2float_lint_double
  (atstype_lint x) { return ((atstype_double)x) ; }
// end of [atspre_g0int2float_lint_double]

#atscode_separator_for_C()

ATSinline()
atstype_int
atspre_g0float2int_float_int
  (atstype_float x) { return ((atstype_int)x) ; }
ATSinline()
atstype_lint
atspre_g0float2int_float_lint
  (atstype_float x) { return ((atstype_lint)x) ; }
ATSinline()
atstype_llint
atspre_g0float2int_float_llint
  (atstype_float x) { return ((atstype_llint)x) ; }

ATSinline()
atstype_int
atspre_g0float2int_double_int
  (atstype_double x) { return ((atstype_int)x) ; }
ATSinline()
atstype_lint
atspre_g0float2int_double_lint
  (atstype_double x) { return ((atstype_lint)x) ; }
ATSinline()
atstype_llint
atspre_g0float2int_double_llint
  (atstype_double x) { return ((atstype_llint)x) ; }

#atscode_separator_for_C()

ATSinline()
atstype_float
atspre_g0float2float_float_float (atstype_float x) { return (x) ; }

ATSinline()
atstype_double
atspre_g0float2float_double_double (atstype_double x) { return (x) ; }

ATSinline()
atstype_double
atspre_g0float2float_float_double
(
atstype_float x
)
{
 return ((atstype_double)x) ;
}

ATSinline()
atstype_float
atspre_g0float2float_double_float
(
atstype_double x
)
{
 return ((atstype_float)x) ;
}

#atscode_separator_for_C()
//
extern double atof (const char *inp) ;
//
ATSinline()
atstype_double
atspre_g0string2float_double
  (atstype_string inp) { return atof((char*)inp) ; }
//
#atscode_separator_for_C()

ATSinline()
atstype_float
atspre_g0float_neg_float (atstype_float f) { return (-f) ; }
ATSinline()
atstype_double
atspre_g0float_neg_double (atstype_double f) { return (-f) ; }
ATSinline()
atstype_ldouble
atspre_g0float_neg_ldouble (atstype_ldouble f) { return (-f) ; }

ATSinline()
atstype_float
atspre_g0float_abs_float (atstype_float f) { return (f >= 0 ? f : -f) ; }
ATSinline()
atstype_double
atspre_g0float_abs_double (atstype_double f) { return (f >= 0 ? f : -f) ; }
ATSinline()
atstype_ldouble
atspre_g0float_abs_ldouble (atstype_ldouble f) { return (f >= 0 ? f : -f) ; }

ATSinline()
atstype_float
atspre_g0float_succ_float (atstype_float f) { return (f+1) ; }
ATSinline()
atstype_double
atspre_g0float_succ_double (atstype_double f) { return (f+1) ; }
ATSinline()
atstype_ldouble
atspre_g0float_succ_ldouble (atstype_ldouble f) { return (f+1) ; }

ATSinline()
atstype_float
atspre_g0float_pred_float (atstype_float f) { return (f-1) ; }
ATSinline()
atstype_double
atspre_g0float_pred_double (atstype_double f) { return (f-1) ; }
ATSinline()
atstype_ldouble
atspre_g0float_pred_ldouble (atstype_ldouble f) { return (f-1) ; }

#atscode_separator_for_C()
//
%{
fun
fun_g0float_aop_decl
(
  opr: string, knd: string
) : atext = let
//
val fopr = (
  case+ opr of
  | "add" => "+"
  | "sub" => "-"
  | "mul" => "*"
  | "div" => "/"
  | _(*rest*) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_%s
atspre_g0float_%s_%s
  (atstype_%s f1, atstype_%s f2) { return (f1 %s f2) ; }
// end of [atspre_g0float_%s_%s]\n\
", @(
  knd, opr, knd, knd, knd, fopr, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_g0float_aop_decl]
%}\
//
#fun_g0float_aop_decl("add", "float")\
#fun_g0float_aop_decl("sub", "float")\
#fun_g0float_aop_decl("mul", "float")\
#fun_g0float_aop_decl("div", "float")\
//
#fun_g0float_aop_decl("add", "double")\
#fun_g0float_aop_decl("sub", "double")\
#fun_g0float_aop_decl("mul", "double")\
#fun_g0float_aop_decl("div", "double")\
//
#fun_g0float_aop_decl("add", "ldouble")\
#fun_g0float_aop_decl("sub", "ldouble")\
#fun_g0float_aop_decl("mul", "ldouble")\
#fun_g0float_aop_decl("div", "ldouble")\
//
extern atstype_float fmodf (atstype_float, atstype_float) ;
extern atstype_double fmod (atstype_double, atstype_double) ;
extern atstype_ldouble fmodl (atstype_ldouble, atstype_ldouble) ;
//
ATSinline()
atstype_float
atspre_g0float_mod_float
  (atstype_float f1, atstype_float f2) { return fmodf(f1, f2) ; }
ATSinline()
atstype_double
atspre_g0float_mod_double
  (atstype_double f1, atstype_double f2) { return fmod(f1, f2) ; }
ATSinline()
atstype_ldouble
atspre_g0float_mod_ldouble
  (atstype_ldouble f1, atstype_ldouble f2) { return fmodl(f1, f2) ; }
//
#atscode_separator_for_C()
//
%{
fun
fun_g0float_cmp_decl (
  opr: string, knd: string
) : atext = let
//
val fopr =
(
  case+ opr of
  | "lt" => "<" | "lte" => "<="
  | "gt" => ">" | "gte" => ">="
  | "eq" => "==" | "neq" => "!="
  | _ (* unprocessed comparison *) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_bool
atspre_g0float_%s_%s
  (atstype_%s f1, atstype_%s f2) {
  return (f1 %s f2 ? atsbool_true : atsbool_false) ;
} // end of [atspre_g0float_%s_%s]\n\
", @(
  opr, knd, knd, knd, fopr, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_g0float_cmp_decl]
%}\
//
#fun_g0float_cmp_decl("lt", "float")\
#fun_g0float_cmp_decl("lte", "float")\
#fun_g0float_cmp_decl("gt", "float")\
#fun_g0float_cmp_decl("gte", "float")\
#fun_g0float_cmp_decl("eq", "float")\
#fun_g0float_cmp_decl("neq", "float")\
//
#fun_g0float_cmp_decl("lt", "double")\
#fun_g0float_cmp_decl("lte", "double")\
#fun_g0float_cmp_decl("gt", "double")\
#fun_g0float_cmp_decl("gte", "double")\
#fun_g0float_cmp_decl("eq", "double")\
#fun_g0float_cmp_decl("neq", "double")\
//
#fun_g0float_cmp_decl("lt", "ldouble")\
#fun_g0float_cmp_decl("lte", "ldouble")\
#fun_g0float_cmp_decl("gt", "ldouble")\
#fun_g0float_cmp_decl("gte", "ldouble")\
#fun_g0float_cmp_decl("eq", "ldouble")\
#fun_g0float_cmp_decl("neq", "ldouble")\
//
#atscode_separator_for_C()

ATSinline()
atstype_int
atspre_g0float_compare_float
(
  atstype_float f1, atstype_float f2
)
{
  if (f1 > f2) return 1 ; else if (f1 < f2) return -1 ; else return 0 ;
} // end of [atspre_g0float_compare_float]

ATSinline()
atstype_int
atspre_g0float_compare_double
(
  atstype_double f1, atstype_double f2
)
{
  if (f1 > f2) return 1 ; else if (f1 < f2) return -1 ; else return 0 ;
} // end of [atspre_g0float_compare_double]

ATSinline()
atstype_int
atspre_g0float_compare_ldouble
(
  atstype_ldouble f1, atstype_ldouble f2
)
{
  if (f1 > f2) return 1 ; else if (f1 < f2) return -1 ; else return 0 ;
} // end of [atspre_g0float_compare_ldouble]

#atscode_separator_for_C()

ATSinline()
atstype_float
atspre_g0float_min_float
  (atstype_float f1, atstype_float f2) { return (f1 <= f2 ? f1 : f2) ; }
// end of [atspre_g0float_min_float]
ATSinline()
atstype_double
atspre_g0float_min_double
  (atstype_double f1, atstype_double f2) { return (f1 <= f2 ? f1 : f2) ; }
// end of [atspre_g0float_min_double]
ATSinline()
atstype_ldouble
atspre_g0float_min_ldouble
  (atstype_ldouble f1, atstype_ldouble f2) { return (f1 <= f2 ? f1 : f2) ; }
// end of [atspre_g0float_min_ldouble]

ATSinline()
atstype_float
atspre_g0float_max_float
  (atstype_float f1, atstype_float f2) { return (f1 >= f2 ? f1 : f2) ; }
// end of [atspre_g0float_max_float]
ATSinline()
atstype_double
atspre_g0float_max_double
  (atstype_double f1, atstype_double f2) { return (f1 >= f2 ? f1 : f2) ; }
// end of [atspre_g0float_max_double]
ATSinline()
atstype_ldouble
atspre_g0float_max_ldouble
  (atstype_ldouble f1, atstype_ldouble f2) { return (f1 >= f2 ? f1 : f2) ; }
// end of [atspre_g0float_max_ldouble]

#atscode_separator_for_C()
//
%{
fun
fun_aop_int_g0float_decl
(
  opr: string, knd: string
) : atext = let
//
val fopr =
(
  case+ opr of
  | "add" => "+" | "sub" => "-"
  | "mul" => "*" | "div" => "/"
  | _ (* unprocessed operator *) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_%s
atspre_%s_int_%s
  (atstype_int i1, atstype_%s f2) { return (((atstype_%s)i1) %s f2) ; }
// end of [atspre_%s_int_%s]\n\
", @(
  knd, opr, knd, knd, knd, fopr, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_aop_int_g0float_decl]
%}\
//
#fun_aop_int_g0float_decl("add", "float")\
#fun_aop_int_g0float_decl("sub", "float")\
#fun_aop_int_g0float_decl("mul", "float")\
#fun_aop_int_g0float_decl("div", "float")\
//
#fun_aop_int_g0float_decl("add", "double")\
#fun_aop_int_g0float_decl("sub", "double")\
#fun_aop_int_g0float_decl("mul", "double")\
#fun_aop_int_g0float_decl("div", "double")\
//
#fun_aop_int_g0float_decl("add", "ldouble")\
#fun_aop_int_g0float_decl("sub", "ldouble")\
#fun_aop_int_g0float_decl("mul", "ldouble")\
#fun_aop_int_g0float_decl("div", "ldouble")\
//
#atscode_separator_for_C()
//
%{
fun
fun_aop_g0float_int_decl
(
  opr: string, knd: string
) : atext = let
//
val fopr =
(
  case+ opr of
  | "add" => "+" | "sub" => "-"
  | "mul" => "*" | "div" => "/"
  | _ (* unprocessed operator *) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_%s
atspre_%s_%s_int
  (atstype_%s f1, atstype_int i2) { return (f1 %s ((atstype_%s)i2)) ; }
// end of [atspre_%s_%s_int]\n\
", @(
  knd, opr, knd, knd, fopr, knd, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_aop_g0float_int_decl]
%}\
//
#fun_aop_g0float_int_decl("add", "float")\
#fun_aop_g0float_int_decl("sub", "float")\
#fun_aop_g0float_int_decl("mul", "float")\
#fun_aop_g0float_int_decl("div", "float")\
//
#fun_aop_g0float_int_decl("add", "double")\
#fun_aop_g0float_int_decl("sub", "double")\
#fun_aop_g0float_int_decl("mul", "double")\
#fun_aop_g0float_int_decl("div", "double")\
//
#fun_aop_g0float_int_decl("add", "ldouble")\
#fun_aop_g0float_int_decl("sub", "ldouble")\
#fun_aop_g0float_int_decl("mul", "ldouble")\
#fun_aop_g0float_int_decl("div", "ldouble")\
//
#atscode_separator_for_C()
//
%{
fun
fun_cmp_int_g0float_decl
(
  opr: string, knd: string
) : atext = let
//
val fopr =
(
  case+ opr of
  | "lt" => "<" | "lte" => "<="
  | "gt" => ">" | "gte" => ">="
  | "eq" => "==" | "neq" => "!="
  | _ (* unprocessed comparison *) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_bool
atspre_%s_int_%s
  (atstype_int i1, atstype_%s f2) { return (((atstype_%s)i1) %s f2) ; }
// end of [atspre_%s_int_%s]\n\
", @(
  opr, knd, knd, knd, fopr, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_cmp_int_g0float_decl]
%}\
//
#fun_cmp_int_g0float_decl("lt", "float")\
#fun_cmp_int_g0float_decl("lte", "float")\
#fun_cmp_int_g0float_decl("gt", "float")\
#fun_cmp_int_g0float_decl("gte", "float")\
#fun_cmp_int_g0float_decl("eq", "float")\
#fun_cmp_int_g0float_decl("neq", "float")\
//
#fun_cmp_int_g0float_decl("lt", "double")\
#fun_cmp_int_g0float_decl("lte", "double")\
#fun_cmp_int_g0float_decl("gt", "double")\
#fun_cmp_int_g0float_decl("gte", "double")\
#fun_cmp_int_g0float_decl("eq", "double")\
#fun_cmp_int_g0float_decl("neq", "double")\
//
#atscode_separator_for_C()
//
%{
fun
fun_cmp_g0float_int_decl
(
  opr: string, knd: string
) : atext = let
//
val fopr =
(
  case+ opr of
  | "lt" => "<" | "lte" => "<="
  | "gt" => ">" | "gte" => ">="
  | "eq" => "==" | "neq" => "!="
  | _ (* unprocessed comparison *) => opr
) : string // end of [val]
//
val ent = sprintf
("\
ATSinline()
atstype_bool
atspre_%s_%s_int
  (atstype_%s f1, atstype_int i2) { return (f1 %s ((atstype_%s)i2)) ; }
// end of [atspre_%s_%s_int]\n\
", @(
  opr, knd, knd, fopr, knd, opr, knd
)
) // end of [sprintf] // end of [val]
//
in
  atext_strptr (ent)
end // end of [fun_cmp_int_g0float_decl]
%}\
//
#fun_cmp_g0float_int_decl("lt", "float")\
#fun_cmp_g0float_int_decl("lte", "float")\
#fun_cmp_g0float_int_decl("gt", "float")\
#fun_cmp_g0float_int_decl("gte", "float")\
#fun_cmp_g0float_int_decl("eq", "float")\
#fun_cmp_g0float_int_decl("neq", "float")\
//
#fun_cmp_g0float_int_decl("lt", "double")\
#fun_cmp_g0float_int_decl("lte", "double")\
#fun_cmp_g0float_int_decl("gt", "double")\
#fun_cmp_g0float_int_decl("gte", "double")\
#fun_cmp_g0float_int_decl("eq", "double")\
#fun_cmp_g0float_int_decl("neq", "double")\
//
#atscode_separator_for_C()

\#endif // ifndef ATSLIB_PRELUDE_CATS_FLOAT

#atscode_separator_for_C()

#atscode_eof_strsub_for_C("\#thisfilename$")

%{
implement
main (argc, argv) = fprint_filsub (stdout_ref, "float_atxt.txt")
%}\