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?
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?
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?
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?