Clamping Values

Is there some kind of template way to convert a value, say int, to meet a
universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions clamp
the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the quantifier,
or perhaps that is a macro and one already exists?

Related to min/max clamping, what does this do:

val x: uint16 = cast{uint16}(5)
val y: uint8 = cast{uint8}(x)

Does it actually copy memory from a uint16_t to a uint8_t? Does it just
take the least significant byte? Does it reuse memory? Does it just play a
dangerous pointer game?On Tuesday, November 3, 2015 at 6:39:26 PM UTC-7, gmhwxi wrote:

fun{}
clamp
{l,u:int | l <= u}
(
l: int(l), x: int, u: int(u)
) : intBtwe(l,u) =
let val x = g1ofg0(x) in min(max(l, x), u) end

On Tue, Nov 3, 2015 at 8:30 PM, Mike Jones <pro...@gmail.com <javascript:>> wrote:

Is there some kind of template way to convert a value, say int, to meet a
universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions
clamp the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the
quantifier, or perhaps that is a macro and one already exists?


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...@googlegroups.com <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com?utm_medium=email&utm_source=footer
.

Say you write the following code in C:

uint16_t x = 5;
uint8_t y = x;

Casting is implicitly done. It is really equivalent to writing:

uint16_t x = (uint16_t)5;
uint8_t y = (uint8_t)x;

In ATS casting needs to be done explicitly.On Tuesday, November 3, 2015 at 10:01:50 PM UTC-5, Mike Jones wrote:

Related to min/max clamping, what does this do:

val x: uint16 = cast{uint16}(5)
val y: uint8 = cast{uint8}(x)

Does it actually copy memory from a uint16_t to a uint8_t? Does it just
take the least significant byte? Does it reuse memory? Does it just play a
dangerous pointer game?

On Tuesday, November 3, 2015 at 6:39:26 PM UTC-7, gmhwxi wrote:

fun{}
clamp
{l,u:int | l <= u}
(
l: int(l), x: int, u: int(u)
) : intBtwe(l,u) =
let val x = g1ofg0(x) in min(max(l, x), u) end

On Tue, Nov 3, 2015 at 8:30 PM, Mike Jones pro...@gmail.com wrote:

Is there some kind of template way to convert a value, say int, to meet
a universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions
clamp the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the
quantifier, or perhaps that is a macro and one already exists?


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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com?utm_medium=email&utm_source=footer
.

I think, if I understand correctly, there are a lot like this. Here’s
the one for your case:
https://github.com/githwxi/ATS-Postiats/search?utf8=✓&q=intBtwOn Tue, Nov 3, 2015 at 8:30 PM, Mike Jones proc...@gmail.com wrote:

Is there some kind of template way to convert a value, say int, to meet a
universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions clamp
the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the quantifier,
or perhaps that is a macro and one already exists?


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 post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com.

Brandon Barker
brandon...@gmail.com

A type in C is just like shoe size.

In the following code, both x and y are values:

val x: uint16 = cast{uint16}(5)
val y: uint8 = cast{uint8}(x)

Most likely, the C compiler is to replace x and y with the constant 5
in this particular case.

Does it actually copy memory from a uint16_t to a uint8_t?

It could but it is very unlikely. Compilers like gcc and clang are very good
at performing all sorts of optimizations. I could not think of anything
dangerous
in this case.On Tuesday, November 3, 2015 at 10:01:50 PM UTC-5, Mike Jones wrote:

Related to min/max clamping, what does this do:

val x: uint16 = cast{uint16}(5)
val y: uint8 = cast{uint8}(x)

Does it actually copy memory from a uint16_t to a uint8_t? Does it just
take the least significant byte? Does it reuse memory? Does it just play a
dangerous pointer game?

On Tuesday, November 3, 2015 at 6:39:26 PM UTC-7, gmhwxi wrote:

fun{}
clamp
{l,u:int | l <= u}
(
l: int(l), x: int, u: int(u)
) : intBtwe(l,u) =
let val x = g1ofg0(x) in min(max(l, x), u) end

On Tue, Nov 3, 2015 at 8:30 PM, Mike Jones pro...@gmail.com wrote:

Is there some kind of template way to convert a value, say int, to meet
a universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions
clamp the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the
quantifier, or perhaps that is a macro and one already exists?


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...@googlegroups.com.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com?utm_medium=email&utm_source=footer
.

fun{}
clamp
{l,u:int | l <= u}
(
l: int(l), x: int, u: int(u)
) : intBtwe(l,u) =
let val x = g1ofg0(x) in min(max(l, x), u) endOn Tue, Nov 3, 2015 at 8:30 PM, Mike Jones proc...@gmail.com wrote:

Is there some kind of template way to convert a value, say int, to meet a
universal like {n:int | n > 3; n < 6} ?

Mainly to avoid writing functions for these cases. min/max functions clamp
the value, but don’t deal with the quantifier.

Perhaps what I am looking for is a template that generates the quantifier,
or perhaps that is a macro and one already exists?


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 post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/00523f2c-59d4-4582-b07e-a48d42ba6601%40googlegroups.com?utm_medium=email&utm_source=footer
.