File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
include/fixed_point/inline Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -493,15 +493,16 @@ FXP_DECLARATION(frac f_clip (frac x, frac limit))
493493 */
494494FXP_DECLARATION (dfrac df_addsat (dfrac x1 , dfrac x2 ))
495495{
496- dfrac_base result = x1 .v + x2 .v ;
497496 dfrac r ;
498497
499- if (x1 .v > 0 && x2 .v > 0 )
500- r .v = ((result < x1 .v ) ? DFRAC_MAX_V : result );
501- else if (x1 .v < 0 && x2 .v < 0 )
502- r .v = ((result > x1 .v ) ? DFRAC_MIN_V : result );
498+ /* The compiler does not seem to generate nice code for the
499+ * implementation below: */
500+
501+ if (x1 .v >= 0 )
502+ r .v = (x2 .v > DFRAC_MAX_V - x1 .v )? DFRAC_MAX_V : x1 .v + x2 .v ;
503503 else
504- r .v = result ;
504+ r .v = (x2 .v < DFRAC_MIN_V - x1 .v ) ? DFRAC_MIN_V : x1 .v + x2 .v ;
505+
505506
506507 return r ;
507508}
You can’t perform that action at this time.
0 commit comments