bit operations

18 views
Skip to first unread message

ice.r...@gmail.com

unread,
Jul 8, 2020, 5:33:22 AM7/8/20
to ats-lang-users

Hi,
I was not able to find bit operations
in ATS, like &, |, <<, >>.

Does ATS supports them?

Hongwei Xi

unread,
Jul 8, 2020, 10:30:23 AM7/8/20
to ats-lan...@googlegroups.com
You can find these operations in prelude/SATS/integer.sats
There are called:
lnot (for ~),
land (for &), lor (for |), lxor (for ^), lsl (for <<), and lsr (for >>).

These operations are for unsigned ints. For signed ints, there
are asl (for <<) and asr (for >>).

In ATS2, there is no implicit casting. You may have to cast a
signed int into an unsigned int explicitly in order to perform a bit
operation.


--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/04b44a32-88e3-4855-acb9-ed7bdcc3391en%40googlegroups.com.

Dambaev Alexander

unread,
Jul 8, 2020, 10:56:59 AM7/8/20
to ats-lan...@googlegroups.com
Thanks, I will check it out

ср, 8 июл. 2020 г. в 14:30, Hongwei Xi <gmh...@gmail.com>:

Hongwei Xi

unread,
Jul 8, 2020, 11:10:30 AM7/8/20
to ats-lan...@googlegroups.com
In general, if you want to call a C function in ATS,
you can just use 'extfcall' for external function calls.
Of course, if you do so, you bypass ATS type-checking.
Here is an example:

%{^
int lsl(uint u, int n) { return (u << n); }
int lsr(uint u, int n) { return (u >> n); }
%}

implement
main0() =
{
val
pow_2_10 =
$extfcall(uint, "lsl", 1, 10)
val () = println!("pow_2_10 = ", pow_2_10)
}

Dambaev Alexander

unread,
Jul 8, 2020, 11:19:52 AM7/8/20
to ats-lan...@googlegroups.com
Yes, thanks. I know about $extfcall and use it, just wanted to use more things from standard library.

And yes, sometimes explicit casts are painful in terms of searching for specific cast function.

ср, 8 июл. 2020 г. в 15:10, Hongwei Xi <gmh...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages