summaryrefslogtreecommitdiffstats
path: root/usr.bin/awk/tran.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2020-12-18 21:36:24 +0000
committermillert <millert@openbsd.org>2020-12-18 21:36:24 +0000
commit6de80fb8e30bbd35e9dda3cc355f04a2d5820ace (patch)
treeaf099742b4cee770f6f42282531bef59f2c01446 /usr.bin/awk/tran.c
parentAdd glue for the USB3 controller on the i.MX8MP SoC. NXP had this glue for (diff)
downloadwireguard-openbsd-6de80fb8e30bbd35e9dda3cc355f04a2d5820ace.tar.xz
wireguard-openbsd-6de80fb8e30bbd35e9dda3cc355f04a2d5820ace.zip
Update awk to December 18, 2020 version.
Includes the official fix for +-inf and +-nan handling.
Diffstat (limited to 'usr.bin/awk/tran.c')
-rw-r--r--usr.bin/awk/tran.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/usr.bin/awk/tran.c b/usr.bin/awk/tran.c
index 1ea64d240d8..41a0faa4a4d 100644
--- a/usr.bin/awk/tran.c
+++ b/usr.bin/awk/tran.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tran.c,v 1.32 2020/12/09 20:00:11 millert Exp $ */
+/* $OpenBSD: tran.c,v 1.33 2020/12/18 21:36:24 millert Exp $ */
/****************************************************************
Copyright (C) Lucent Technologies 1997
All Rights Reserved
@@ -419,10 +419,21 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
return(vp->fval);
}
+static char *get_inf_nan(double d)
+{
+ if (isinf(d)) {
+ return (d < 0 ? "-inf" : "+inf");
+ } else if (isnan(d)) {
+ return (signbit(d) != 0 ? "-nan" : "+nan");
+ } else
+ return NULL;
+}
+
static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cell */
{
int n;
double dtemp;
+ char *p;
if ((vp->tval & (NUM | STR)) == 0)
funnyvar(vp, "read value of");
@@ -459,7 +470,9 @@ static char *get_str_val(Cell *vp, char **fmt) /* get string val of a Cel
{ \
if (freeable(vp)) \
xfree(vp->sval); \
- if (modf(vp->fval, &dtemp) == 0) /* it's integral */ \
+ if ((p = get_inf_nan(vp->fval)) != NULL) \
+ n = (vp->sval = strdup(p)) ? 0 : -1; \
+ else if (modf(vp->fval, &dtemp) == 0) /* it's integral */ \
n = asprintf(&vp->sval, "%.30g", vp->fval); \
else \
n = asprintf(&vp->sval, *fmt, vp->fval); \