File: rtest_decfp.mac

package info (click to toggle)
maxima 5.49.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 128,980 kB
  • sloc: lisp: 437,854; fortran: 14,665; tcl: 10,143; sh: 4,598; makefile: 2,204; ansic: 447; java: 374; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (88 lines) | stat: -rw-r--r-- 2,247 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Tests for decimal floats, basically copied from the decfp-core.lisp
 */

(kill(all),
 if not ?boundp('rounddecimalfloats) then load(decfp),
 sum:0
 );
0;

(for i: 1 thru 50 do sum:sum+decbfloat(9/10^i), is(sum < 1));
true;

is(sum+1/10^50=1.0L0);
true;

rationalize(1.0L-1)-1/10;
0;

/* Test that orderlessp is a total ordering on mixed binary and decimal bigfloats. */
block(
	/* Some special values that have very similar internal representations ... */
	[zb1 : block([fpprec : 1], bfloat(0.0)),
	 zb2 : block([fpprec : 2], bfloat(0.0)),
	 zd1 : block([fpprec : 1], bfloat(0)),
	 zd2 : block([fpprec : 2], bfloat(0)),
	 zd6 : block([fpprec : 6], bfloat(0)),
	 zd9 : block([fpprec : 9], bfloat(0)),
	 b1 : block([fpprec : 1], bfloat(1.0)),
	 b2 : block([fpprec : 2], bfloat(1.0)),
	 d1 : block([fpprec : 1], bfloat(320)),
	 d2 : block([fpprec : 2], bfloat(320)),
	 d6 : block([fpprec : 6], bfloat(320)),
	 d9 : block([fpprec : 9], bfloat(320)),
	 L, fpprec : fpprec],
	local(orderlessp),
	
	/* totalorderp by Stavros Macrakis */
	totalorderp(func, domain) := block(
		[ord, i, j, res : []],
		ord : sort(domain, func),
		i : 0,
		for eli in ord do (
			i : i + 1,
			j : 0,
			for elj in ord do (
				j : j + 1,
				if func(eli, elj) # is(i < j) and not(eli = elj) then push([i, j, eli, elj], res)
			)
		),
		res
	),
	
	L : [b1, b2, d1, d2, d6, d9],
	
	/* Add the negatives.  */
	L : append(L, -L),
	
	/* Add different zeros. */
	L : append(L, [zb1, zb2, zd1, zd2, zd6, zd9]),
	
	/* Throw in some more.  */
	for i in [-4, -3, -2, -1, 1, 2, 3, 4] do (
		for fpprec : 1 thru 11 step 2 do (
			/* bfloat will turn integers into decimal bigfloats
			   and floats into binary bigfloats. */
			push(bfloat(25 * i), L),
			push(bfloat(25.0 * i), L),
			push(bfloat(5 * i), L),
			push(bfloat(5.0 * i), L),
			push(bfloat(i), L),
			push(bfloat(1.0 * i), L),
			push(bfloat(i / 5), L),
			push(bfloat(i / 5.0), L),
			push(bfloat(i / 25), L),
			push(bfloat(i / 25.0), L)
		)
	),
	
	/* Test for total order. */
	totalorderp(orderlessp, L)
);
[];

/* The decfp code changes the value of bigfloatone (and possibly other 
such values) to decimal floats. Let's reset them. */
(reset(?\*bfmhalf\*,?\*bfhalf\*,?\*bigfloatone\*,?\*bigfloatzero\*),0);
0$