[GitHub] mlampert commented on a change in pull request #947: Refactor/easing library

2018-03-30 Thread GitBox
mlampert commented on a change in pull request #947: Refactor/easing library
URL: https://github.com/apache/mynewt-core/pull/947#discussion_r178368672
 
 

 ##
 File path: util/easing/src/easing.c
 ##
 @@ -69,125 +69,128 @@ static inline float quadratic_in(float step, float 
max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 2);
+   return max_val * (ratio * ratio);
 }
 
 static inline float quadratic_out(float step, float max_steps, float max_val)
 {
 float ratio = step / max_steps;
 
-   return -max_val * ratio * (ratio - 2.0);
+   return -max_val * ratio * (ratio - 2.0f);
 }
 
 static inline float quadratic_io(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps / 2.0);
+   float ratio = step / (max_steps / 2.0f);
 
if (ratio < 1)
-   return max_val / 2.0 * pow(ratio, 2);
+   return max_val / 2.0f * (ratio * ratio);
 
-ratio = (step - (max_steps/2.0)) / (max_steps/2.0);
-return (max_val / 2.0) - (max_val / 2.0) * ratio * (ratio - 2.0);
+ratio = (step - (max_steps/2.0f)) / (max_steps/2.0f);
+return (max_val / 2.0f) - (max_val / 2.0f) * ratio * (ratio - 2.0f);
 }
 
 /* Cubic */
 static inline float cubic_in(float step, float max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 3);
+   return max_val * (ratio * ratio * ratio);
 
 Review comment:
   Understood - but I cannot answer that question without a reference. The 
interface does not suggest that there is `double` precision involved, it's all 
based on `float` so as a user that's as much as I can expect. In order to 
answer the question if this refactoring falsifies the result we would need a 
definition as to what level of deviation is acceptable.
   
   In addition none of the computations uses accumulation which is where 
`float`'s really start bleeding. All values are monotonically increasing or 
decreasing and the result is converted to a float. So if the initial value and 
the result fits into a `float` then every intermediary value will also fit.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mlampert commented on a change in pull request #947: Refactor/easing library

2018-03-30 Thread GitBox
mlampert commented on a change in pull request #947: Refactor/easing library
URL: https://github.com/apache/mynewt-core/pull/947#discussion_r178368672
 
 

 ##
 File path: util/easing/src/easing.c
 ##
 @@ -69,125 +69,128 @@ static inline float quadratic_in(float step, float 
max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 2);
+   return max_val * (ratio * ratio);
 }
 
 static inline float quadratic_out(float step, float max_steps, float max_val)
 {
 float ratio = step / max_steps;
 
-   return -max_val * ratio * (ratio - 2.0);
+   return -max_val * ratio * (ratio - 2.0f);
 }
 
 static inline float quadratic_io(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps / 2.0);
+   float ratio = step / (max_steps / 2.0f);
 
if (ratio < 1)
-   return max_val / 2.0 * pow(ratio, 2);
+   return max_val / 2.0f * (ratio * ratio);
 
-ratio = (step - (max_steps/2.0)) / (max_steps/2.0);
-return (max_val / 2.0) - (max_val / 2.0) * ratio * (ratio - 2.0);
+ratio = (step - (max_steps/2.0f)) / (max_steps/2.0f);
+return (max_val / 2.0f) - (max_val / 2.0f) * ratio * (ratio - 2.0f);
 }
 
 /* Cubic */
 static inline float cubic_in(float step, float max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 3);
+   return max_val * (ratio * ratio * ratio);
 
 Review comment:
   Understood - but I cannot answer that question without a reference. The 
interface does not suggest that there is `double` precision involved, it's all 
based on `float` so as a user that's as much as I can expect. In order to 
answer the question if this refactoring falsifies the result we would need a 
definition as to what level of deviation is acceptable.
   
   In addition none of the computations uses accumulation which is where 
`float`'s really start bleeding, all values are monotonically increasing or 
decreasing and the result is converted to a float. So if the initial value and 
the result fits into a `float` then every intermediary value will also fit.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mlampert commented on a change in pull request #947: Refactor/easing library

2018-03-30 Thread GitBox
mlampert commented on a change in pull request #947: Refactor/easing library
URL: https://github.com/apache/mynewt-core/pull/947#discussion_r178368006
 
 

 ##
 File path: util/easing/src/easing.c
 ##
 @@ -43,12 +43,12 @@ static inline float exponential_out(float step, float 
max_steps, float max_val)
 {
return (step == max_steps) ?
 max_val :
-max_val - pow(max_val, 1.0 - (float)step/max_steps);
+max_val - pow(max_val, 1.0f - (float)step/max_steps);
 
 Review comment:
   I'm not sure why the original implementation had that cast there, it was 
promoted to a `double` anyway. I presume that early on `step` and `max_step` 
were integer values and it was a remnant of refactoring. I can certainly clean 
those up.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] mlampert commented on a change in pull request #947: Refactor/easing library

2018-03-30 Thread GitBox
mlampert commented on a change in pull request #947: Refactor/easing library
URL: https://github.com/apache/mynewt-core/pull/947#discussion_r178365725
 
 

 ##
 File path: util/easing/src/easing.c
 ##
 @@ -69,125 +69,128 @@ static inline float quadratic_in(float step, float 
max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 2);
+   return max_val * (ratio * ratio);
 }
 
 static inline float quadratic_out(float step, float max_steps, float max_val)
 {
 float ratio = step / max_steps;
 
-   return -max_val * ratio * (ratio - 2.0);
+   return -max_val * ratio * (ratio - 2.0f);
 }
 
 static inline float quadratic_io(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps / 2.0);
+   float ratio = step / (max_steps / 2.0f);
 
if (ratio < 1)
-   return max_val / 2.0 * pow(ratio, 2);
+   return max_val / 2.0f * (ratio * ratio);
 
-ratio = (step - (max_steps/2.0)) / (max_steps/2.0);
-return (max_val / 2.0) - (max_val / 2.0) * ratio * (ratio - 2.0);
+ratio = (step - (max_steps/2.0f)) / (max_steps/2.0f);
+return (max_val / 2.0f) - (max_val / 2.0f) * ratio * (ratio - 2.0f);
 }
 
 /* Cubic */
 static inline float cubic_in(float step, float max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 3);
+   return max_val * (ratio * ratio * ratio);
 }
 
 static inline float cubic_out(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps - 1.0);
+   float ratio = step / (max_steps - 1.0f);
 
-   return max_val * (pow(ratio, 3) + 1);
+   return max_val * ((ratio * ratio * ratio) + 1);
 }
 
 static inline float cubic_io(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps / 2.0);
+   float ratio = step / (max_steps / 2.0f);
 
if (ratio < 1)
-   return max_val / 2 * pow(ratio, 3);
+   return max_val / 2 * (ratio * ratio * ratio);
 
-   return max_val / 2 * (pow(ratio - 2, 3) + 2);
+ratio -= 2;
+   return max_val / 2 * ((ratio * ratio * ratio) + 2);
 }
 
 /* Quartic */
 static inline float quartic_in(float step, float max_steps, float max_val)
 {
float ratio = step / max_steps;
 
-   return max_val * pow(ratio, 4);
+   return max_val * (ratio * ratio * ratio * ratio);
 }
 
 static inline float quartic_out(float step, float max_steps, float max_val)
 {
-   float ratio = (step / max_steps) - 1.0;
+   float ratio = (step / max_steps) - 1.0f;
 
-   return max_val + max_val * pow(ratio, 5);
+   return max_val + max_val * (ratio * ratio * ratio * ratio * ratio);
 }
 
 static inline float quartic_io(float step, float max_steps, float max_val)
 {
-   float ratio = step / (max_steps / 2.0);
+   float ratio = step / (max_steps / 2.0f);
 
if (ratio < 1)
-   return max_val / 2 * pow(ratio, 4);
+   return max_val / 2 * (ratio * ratio * ratio * ratio);
 
-   return max_val + max_val / 2 * pow(ratio -2, 5);
+ratio -= 2;
 
 Review comment:
   the weird identation comes from the original source code having tab 
characters in some places and github uses tabstop=8. I didn't clean up the tabs 
because it introduces a lot of noise into the code review but can certainly do 
that.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services