diff options
author | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
---|---|---|
committer | roberto <roberto@FreeBSD.org> | 1999-12-09 13:01:21 +0000 |
commit | ef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch) | |
tree | fc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/tsftomsu.c | |
download | FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz |
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/tsftomsu.c')
-rw-r--r-- | contrib/ntp/libntp/tsftomsu.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/tsftomsu.c b/contrib/ntp/libntp/tsftomsu.c new file mode 100644 index 0000000..5926aab --- /dev/null +++ b/contrib/ntp/libntp/tsftomsu.c @@ -0,0 +1,38 @@ +/* + * tsftomsu - convert from a time stamp fraction to milliseconds + */ +#include "ntp_fp.h" +#include "ntp_stdlib.h" + +int +tsftomsu( + u_long tsf, + int round + ) +{ + register long val_ui, val_uf; + register long tmp_ui, tmp_uf; + register int i; + + /* + * Essentially, multiply by 10 three times in l_fp form. + * The integral part is the milliseconds. + */ + val_ui = 0; + val_uf = tsf; + for (i = 3; i > 0; i--) { + M_LSHIFT(val_ui, val_uf); + tmp_ui = val_ui; + tmp_uf = val_uf; + M_LSHIFT(val_ui, val_uf); + M_LSHIFT(val_ui, val_uf); + M_ADD(val_ui, val_uf, tmp_ui, tmp_uf); + } + + /* + * Round the value if need be, then return it. + */ + if (round && (val_uf & 0x80000000)) + val_ui++; + return (int)val_ui; +} |