Browse Source

short fixed point <-> double conversion routines; ok henning@

OPENBSD_3_6
alexander 20 years ago
parent
commit
d1a5206262
2 changed files with 28 additions and 2 deletions
  1. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  2. +25
    -1
      src/usr.sbin/ntpd/util.c

+ 3
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.21 2004/07/10 18:42:51 henning Exp $ */
/* $OpenBSD: ntpd.h,v 1.22 2004/07/10 22:24:20 alexander Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -212,3 +212,5 @@ double gettime(void);
void d_to_tv(double, struct timeval *); void d_to_tv(double, struct timeval *);
double lfp_to_d(struct l_fixedpt); double lfp_to_d(struct l_fixedpt);
struct l_fixedpt d_to_lfp(double); struct l_fixedpt d_to_lfp(double);
double sfp_to_d(struct s_fixedpt);
struct s_fixedpt d_to_sfp(double);

+ 25
- 1
src/usr.sbin/ntpd/util.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.7 2004/07/07 07:38:21 henning Exp $ */
/* $OpenBSD: util.c,v 1.8 2004/07/10 22:24:20 alexander Exp $ */
/* /*
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org> * Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
@ -62,3 +62,27 @@ d_to_lfp(double d)
return (lfp); return (lfp);
} }
double
sfp_to_d(struct s_fixedpt sfp)
{
double ret;
sfp.int_part = ntohs(sfp.int_part);
sfp.fraction = ntohs(sfp.fraction);
ret = (double)(sfp.int_part) + ((double)sfp.fraction / USHRT_MAX);
return (ret);
}
struct s_fixedpt
d_to_sfp(double d)
{
struct s_fixedpt sfp;
sfp.int_part = htons((u_int16_t)d);
sfp.fraction = htons((u_int16_t)((d - (u_int16_t)d) * USHRT_MAX));
return (sfp);
}

Loading…
Cancel
Save