How can a floating point number be converted into an integer in ATS?

68 Views Asked by At

For instance, I need to turn the number 3.14 (of the type double) into 3 (of the type int). I tried double2int but it did not work. I also tried floor, but it did not work, either.

1

There are 1 best solutions below

0
On

You should use g0float2int.

For example:

#include
"share/atspre_staload.hats"
#include
"share/atspre_staload_libats_ML.hats"

implement main0() = ()

val double_pi:double = 3.14
val int_pi:int = g0float2int(double_pi) 

val () = println!(double_pi)
val () = println!(int_pi)

You might be confused because there is a function in the ATS codebase called double2int, but it is unique to the libraries used to target certain languages like JavaScript, etc.