Michal Lenc commented: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/726#note_132779


Hello, removing `abs` without any other change is not correct imo, this would 
automatically discard possible bittimings with `sample point > 
sample_point_nominal` as the subtraction' result is negative, thus largest 
error in unsigned arithmetic.

Calling `abs` leads to implicit conversion to signed value I think, so the 
original code is technically correct. For example the following code prints 
`0x2` instead of `0xff..fe` it would without `abs`.

```c
  unsigned int a = 0x7;
  unsigned int b = 0x9;

  unsigned int c = abs(a - b);
  printf("0x%x\n", c);
```

It's true `-Wabsolute-value` leads to a warning, interestingly it only detects 
`unsigned int`. If you replace it with `uint8_t`, it passes.

I think we can either make subtraction operands signed, or just remove `abs` 
and have something like

```c
sample_point_error = sample_point_nominal > sample_point ?
                     sample_point_nominal - sample_point :
                     sample_point - sample_point_nominal;
```

-- 
View it on GitLab: 
https://gitlab.rtems.org/rtems/rtos/rtems/-/merge_requests/726#note_132779
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to