fixeria has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-trx/+/43161?usp=email )
Change subject: Transceiver52M: use lround() for TRXD toa/ci rounding
......................................................................
Transceiver52M: use lround() for TRXD toa/ci rounding
trxd_fill_v0_specific() and trxd_fill_v1_specific() rounded bi->toa
and bi->ci to the nearest integer using the "+ 0.5, then truncate"
idiom. That only rounds correctly for non-negative inputs: for
negative values (toa can be negative for an early burst, ci can be
negative under poor C/I conditions) it biases towards zero instead
of rounding to nearest, e.g. -1.3 + 0.5 = -0.8, truncated to 0
instead of the correct -1.
Use lround() instead, which rounds-half-away-from-zero correctly
for both signs.
Change-Id: I0c52f1b91070e4750a8a0ffbccb222454e694c3b
Related: OS#5283
---
M Transceiver52M/proto_trxd.c
1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/61/43161/1
diff --git a/Transceiver52M/proto_trxd.c b/Transceiver52M/proto_trxd.c
index e5a889d..638f7f3 100644
--- a/Transceiver52M/proto_trxd.c
+++ b/Transceiver52M/proto_trxd.c
@@ -38,7 +38,7 @@
int toa_int;
/* in 1/256 symbols, round to closest integer */
- toa_int = (int) (bi->toa * 256.0 + 0.5);
+ toa_int = (int) lround(bi->toa * 256.0);
v0->rssi = bi->rssi;
osmo_store16be(toa_int, &v0->toa);
}
@@ -48,7 +48,7 @@
int16_t ci_int_cB;
/* deciBels->centiBels, round to closest integer */
- ci_int_cB = (int16_t)((bi->ci * 10) + 0.5);
+ ci_int_cB = (int16_t) lround(bi->ci * 10.0);
v1->idle = !!bi->idle;
v1->modulation = (bi->modulation == MODULATION_GMSK) ?
--
To view, visit https://gerrit.osmocom.org/c/osmo-trx/+/43161?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Change-Id: I0c52f1b91070e4750a8a0ffbccb222454e694c3b
Gerrit-Change-Number: 43161
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>