Unnamed Fossil Project

Check-in [8b57721245]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Change qround() to round to even on ties.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 8b577212453d0356f554549fd92e82c4ba377b37
User & Date: dgp 2013-05-09 14:17:12
Context
2013-05-09
14:51
Bump for a release of version 1.2. check-in: 5d0b7b082a user: dgp tags: trunk
14:17
Change qround() to round to even on ties. check-in: 8b57721245 user: dgp tags: trunk
12:57
Added a test to check that the mpexpr precision variable is handled on a per-interpreter basis (with the old version this was not the case) check-in: bb6410d6f3 user: arjenmarkus tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/qfunc.c.

707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
...
728
729
730
731
732
733
734
735
736






737
738
739
740
741
742
743
 */
NUMBER *
qround(q, places)
	NUMBER *q;		/* number to be rounded */
	long places;		/* number of decimal places to round to */
{
	NUMBER *r;
	ZVALUE tenpow, roundval, tmp1, tmp2;

	if (places < 0)
		math_error("Negative places for qround");
	if (qisint(q))
		return qlink(q);
	/*
	 * Calculate one half of the denominator, ignoring fractional results.
................................................................................
	 */
	r = qalloc();
	ztenpow(places, &tenpow);
	zmul(q->num, tenpow, &tmp2);
	zadd(tmp2, roundval, &tmp1);
	zfree(tmp2);
	zfree(roundval);
	zquo(tmp1, q->den, &tmp2);
	zfree(tmp1);






	if (ziszero(tmp2)) {
		zfree(tmp2);
		return qlink(&_qzero_);
	}
	/*
	 * Now reduce the result to the lowest common denominator.
	 */






|







 







|

>
>
>
>
>
>







707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
...
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
 */
NUMBER *
qround(q, places)
	NUMBER *q;		/* number to be rounded */
	long places;		/* number of decimal places to round to */
{
	NUMBER *r;
	ZVALUE tenpow, roundval, tmp1, tmp2, rem;

	if (places < 0)
		math_error("Negative places for qround");
	if (qisint(q))
		return qlink(q);
	/*
	 * Calculate one half of the denominator, ignoring fractional results.
................................................................................
	 */
	r = qalloc();
	ztenpow(places, &tenpow);
	zmul(q->num, tenpow, &tmp2);
	zadd(tmp2, roundval, &tmp1);
	zfree(tmp2);
	zfree(roundval);
	zdiv(tmp1, q->den, &tmp2, &rem);
	zfree(tmp1);
	if (ziszero(rem) && zisodd(tmp2) && ziseven(q->den)) {
		zsub(tmp2, _one_, &tmp1);
		zfree(tmp2);
		tmp2 = tmp1;
	}
	zfree(rem);
	if (ziszero(tmp2)) {
		zfree(tmp2);
		return qlink(&_qzero_);
	}
	/*
	 * Now reduce the result to the lowest common denominator.
	 */