Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: 3.1.6-pws-4: floating point support



On Sep 17,  2:23pm, Peter Stephenson wrote:
} Subject: PATCH: 3.1.6-pws-4: floating point support
}
} Here's my first go at floating point support.
} 
} Outside an immediate numeric context, such as a $((...)) or a normal array
} subscript, there is no special way of telling whether an integer or float
} is required.  So if you need an integer but use a float, the decimal point
} is liable to get in the way.  But that's inevitable.

What's the most appropriate idiom for forcing a floating point number to be
interpreted as an integer, e.g. to force integer division?

The thing that bothers me most -- and I don't know what if anything ksh does
about this, so maybe it's moot -- is that

	((x=y))

where y is float and x was not previously defined, creates x as float, which
may be unexpected (if the assignment is in code that's held over from pre-
float zsh).  This is similar to, but more subtle than, the for-((...))-loop
problem that appears as an example in the doc.  Being required to predeclare
variables with "integer" or "float" from outside the ((...)) context feels
a bit clumsy to me, so I hope there's a better way.

While doing some random fooling around with this, I noticed:

zagzig<23> ((integer florp=9.2))
zsh: bad math expression: unbalanced stack
zagzig<24> typeset -F
florp=9.2000000000

The variable got assigned in spite of the syntax error?  Ouch.

Finally, there's a typo in the doc.

Index: Doc/Zsh/builtins.yo
===================================================================
@@ -348,7 +348,7 @@
 If no var(job) is specified, resume the current job.
 )
 findex(float)
-item(tt(float) [ {tt(PLUE())|tt(-)}tt(EFghlrtux) ] [ var(name)[tt(=)var(value)] ... ])(
+item(tt(float) [ {tt(PLUS())|tt(-)}tt(EFghlrtux) ] [ var(name)[tt(=)var(value)] ... ])(
 Equivalent to tt(typeset -E), except that options irrelevant to floating
 point numbers are not permitted.
 )

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author