<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><blockquote type="cite"><div><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">I mean, constants like "1 / 2.75" will sure be evaluated at compile time.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">And even if not, it's just a division, nothing expensive.</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"></div></blockquote><div><br></div><div>Do you know where in the docs it says that will happen? I couldn't find anything as reassurance, and I assumed then that a floating point division would take place, at that point, every time, which feels inefficient, given that it is in fact a constant and should require zero calculation at runtime.<br></div><div><br></div><div>Expensive is relative I guess. I come from the days when a 1MHz CPU was considered exotic.</div><div><br></div><br><blockquote type="cite"><div><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">Volker</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><blockquote type="cite" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br>Volker<br><br><br>Am Freitag, dem 18.08.2023 um 09:26 +0100 schrieb Sean Charles<br>(emacstheviking):<br><blockquote type="cite">I am currently working on a simple 2D game engine using raylib, all good.<br>I'm implementing a tweening library based on -the- easing equations by<br>Robert Penner.<br><br>The ones I need I have implemented, but I don't think I will need the<br>complete set. On implementing the easeInBounce, easeOutBounce and<br>easeInOutBounce, using this as my guide, the raylib Rust easing<br>source: https://docs.rs/raylib/latest/src/raylib/ease.rs.html#242-256 , I<br>noticed that there are some constants which I decided I didn't want to<br>have to recalculate at run time.<br><br>In a game loop, anything you can do to save pointless repetition means<br>more rendering time between frames.<br><br>This MIGHT be over eager optimisation I guess as all I am doing at the<br>moment is a simple proof-of-concept for a 2D engine which I will then port<br>over as the core of my transpiler IDE I have started.<br><br>Here is what I ended up for as the implementation of easeOutBounce, I<br>decided to use the apostrophe naming rule so that the code reads like the<br>source code, and I also did this because I wasn't really sure what those<br>constants are for, I have a rough idea but I couldn't decide on an<br>effectively communicable name for the source so I opted to call them what<br>they do!<br><br><br>tween_(bounce_out, Time, Range, Duration) = V :-<br> <span class="Apple-converted-space"> </span>Percent = Time / Duration,<br> <span class="Apple-converted-space"> </span>( if Percent < '1 / 2.75' then<br> <span class="Apple-converted-space"> </span>V = Range * n1 * Percent * Percent<br><br> <span class="Apple-converted-space"> </span>else if Percent < '2 / 2.75' then<br> <span class="Apple-converted-space"> </span>Td1 = Percent - '1.5 / 2.75',<br> <span class="Apple-converted-space"> </span>V = Range * ( n1 * Td1 * Td1 +0.75 )<br><br> <span class="Apple-converted-space"> </span>else if Percent < '2.5 / 2.75' then<br> <span class="Apple-converted-space"> </span>Td1 = Percent - '2.25 / 2.75',<br> <span class="Apple-converted-space"> </span>V = Range * ( n1 * Td1 * Td1 +0.9375 )<br> <span class="Apple-converted-space"> </span>else<br> <span class="Apple-converted-space"> </span>Td1 = Percent - '2.625 / 2.75',<br> <span class="Apple-converted-space"> </span>V = Range * ( n1 * Td1 * Td1 + 0.984375 )<br> <span class="Apple-converted-space"> </span>),<br> <span class="Apple-converted-space"> </span>trace [io(!IO)] (<br> <span class="Apple-converted-space"> </span>io.format("bounce_out: %f\n", [f(V)], !IO)<br> <span class="Apple-converted-space"> </span>).<br><br>The above code then make suse of the following constants, I read somewhere<br>that small functions are automatically inlined (but not 100% sure I read<br>it) so I explicitly made then inlined, the idea being that at runtime,<br>referential transparency would be applied, like in Haskell...<br><br><br> <span class="Apple-converted-space"> </span>% Bounce constants.<br><br>:- pragma inline(func(n1/0)).<br>:- func n1 = (float::out) is det.<br>n1 = 7.5625.<br><br>:- pragma inline(func(d1/0)).<br>:- func d1 = (float::out) is det.<br>d1 = 2.75.<br><br>:- pragma inline(func('1.5 / 2.75'/0)).<br>:- func '1.5 / 2.75' = (float::out) is det.<br>'1.5 / 2.75' = 0.5454.<br><br>:- pragma inline(func('1 / 2.75'/0)).<br>:- func '1 / 2.75' = (float::out) is det.<br>'1 / 2.75' = 0.3636.<br><br>:- pragma inline(func('2 / 2.75'/0)).<br>:- func '2 / 2.75' = (float::out) is det.<br>'2 / 2.75' = 0.7272.<br><br>:- pragma inline(func('2.25 / 2.75'/0)).<br>:- func '2.25 / 2.75' = (float::out) is det.<br>'2.25 / 2.75' = 0.8181.<br><br>:- pragma inline(func('2.5 / 2.75'/0)).<br>:- func '2.5 / 2.75' = (float::out) is det.<br>'2.5 / 2.75' = 0.909.<br><br>:- pragma inline(func('2.625 / 2.75'/0)).<br>:- func '2.625 / 2.75' = (float::out) is det.<br>'2.625 / 2.75' = 0.9545.<br><br>My question is simple this: is what I have done 'ok' or is it a diabolical<br>insult to all that as beautiful and holy in the Mercury world?<br>Could I have used some other aspect / feature of the language?<br><br>Thanks<br>Sean<br><br>_______________________________________________<br>users mailing list<br>users@lists.mercurylang.org<br>https://lists.mercurylang.org/listinfo/users<br></blockquote><br>_______________________________________________<br>users mailing list<br>users@lists.mercurylang.org<br>https://lists.mercurylang.org/listinfo/users<br></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">users mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><a href="mailto:users@lists.mercurylang.org" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">users@lists.mercurylang.org</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><a href="https://lists.mercurylang.org/listinfo/users" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">https://lists.mercurylang.org/listinfo/users</a></div></blockquote></div><br></body></html>