Working with general numbers

A function takes a single number (it could be int , uint , llint , etc)
and divides it with number 10 and return the result . What is the idomatic
way to write such function in ATS.

Here is my code :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/SATS/unsafe.sats”

extern fun{a : t@ype} div (n : a , o : a) : a

implement
div (n , o) = n / o

implement
div (n , o ) = n / o

implement
div (n , o) = n / o

fun{a : t@ype} test (n : a) : a = let
val v = div (n , cast{a}(10))
//val v = n / cast{a}(10)
in v end

implement main0 () = {
val i = 100 : int
val li = 100l : lint
val lli = 100ll : llint
val ui = 100u : uint
val ul = 100ul : ulint
val ull = 100ull : ullint

val () = println! (test (i))
val () = println! (test (ui))

}

Thanks

Here is a more interesting example involving integers of multiple precision:

https://github.com/githwxi/ATS-Postiats-contrib/blob/master/contrib/libats-/hwxi/intinf/TEST/test06.datsOn Sunday, July 6, 2014 9:23:28 AM UTC-4, gmhwxi wrote:

Interface for some generic number operations can be found in
${PATSHOME}/prelude/SATS/gnumber.sats:

https://github.com/githwxi/ATS-Postiats/blob/master/prelude/SATS/CODEGEN/gnumber.atxt

Here is an example using generic numbers:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/INTRO/gfact.dats

On Saturday, July 5, 2014 2:47:34 AM UTC-4, Chotu S wrote:

A function takes a single number (it could be int , uint , llint , etc)
and divides it with number 10 and return the result . What is the idomatic
way to write such function in ATS.

Here is my code :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/SATS/unsafe.sats”

extern fun{a : t@ype} div (n : a , o : a) : a

implement
div (n , o) = n / o

implement
div (n , o ) = n / o

implement
div (n , o) = n / o

fun{a : t@ype} test (n : a) : a = let
val v = div (n , cast{a}(10))
//val v = n / cast{a}(10)
in v end

implement main0 () = {
val i = 100 : int
val li = 100l : lint
val lli = 100ll : llint
val ui = 100u : uint
val ul = 100ul : ulint
val ull = 100ull : ullint

val () = println! (test (i))
val () = println! (test (ui))

}

Thanks

Interface for some generic number operations can be found in
${PATSHOME}/prelude/SATS/gnumber.sats:

Here is an example using generic numbers:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/INTRO/gfact.datsOn Saturday, July 5, 2014 2:47:34 AM UTC-4, Chotu S wrote:

A function takes a single number (it could be int , uint , llint , etc)
and divides it with number 10 and return the result . What is the idomatic
way to write such function in ATS.

Here is my code :

#include “share/atspre_define.hats”
#include “share/atspre_staload.hats”

staload “prelude/SATS/unsafe.sats”

extern fun{a : t@ype} div (n : a , o : a) : a

implement
div (n , o) = n / o

implement
div (n , o ) = n / o

implement
div (n , o) = n / o

fun{a : t@ype} test (n : a) : a = let
val v = div (n , cast{a}(10))
//val v = n / cast{a}(10)
in v end

implement main0 () = {
val i = 100 : int
val li = 100l : lint
val lli = 100ll : llint
val ui = 100u : uint
val ul = 100ul : ulint
val ull = 100ull : ullint

val () = println! (test (i))
val () = println! (test (ui))

}

Thanks