File: double.c

package info (click to toggle)
yforth 0.1beta-12
  • links: PTS
  • area: main
  • in suites: potato
  • size: 352 kB
  • ctags: 787
  • sloc: ansic: 4,415; makefile: 59
file content (174 lines) | stat: -rw-r--r-- 3,435 bytes parent folder | download | duplicates (9)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* yForth? - Written by Luca Padovani (C) 1996/97
 * ------------------------------------------------------------------------
 * This software is FreeWare as long as it comes with this header in each
 * source file, anyway you can use it or any part of it whatever
 * you want. It comes without any warranty, so use it at your own risk.
 * ------------------------------------------------------------------------
 * Module name:     double.c
 * Abstract:        double-number word set
 */

#include <stdio.h>
#include "yforth.h"
#include "core.h"
#include "double.h"

/**************************************************************************/
/* WORDS ******************************************************************/
/**************************************************************************/

void _two_constant() {
	register DCell d = GET_DCELL(sp);
	sp += 2;
	create_definition(A_2CONSTANT);
	compile_cell((Cell) d);
	compile_cell((Cell) (d >> CellBits));
	mark_word(_last);
}

void _two_literal() {
	compile_cell((Cell) _do_literal);
    compile_cell((Cell) sp[1]);
	compile_cell((Cell) _do_literal);
    compile_cell((Cell) sp[0]);
	sp += 2;
}

void _two_variable() {
	create_definition(A_2VARIABLE);
	compile_cell(0);
	compile_cell(0);
	mark_word(_last);
}

void _d_plus() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	d1 += d2;
	sp += 2;
	PUT_DCELL(sp, d1);
}

void _d_minus() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	d1 -= d2;
	sp += 2;
	PUT_DCELL(sp, d1);
}

void _d_dot() {
	register DCell u = GET_DCELL(sp);
	register int usign = u < 0;
	if (usign) u = -u;
	PUT_DCELL(sp, u);
	_less_number_sign();
	_number_sign_s();
	if (usign) {
		*--sp = '-';
		_hold();
	}
	_number_sign_greater();
	_type();
	putchar(' ');
}

void _d_dot_r() {
	register Cell r = *sp++;
	register DCell u = GET_DCELL(sp);
	register int usign = u < 0;
	if (usign && _base == 10) u = -u;
	PUT_DCELL(sp, u);
	_less_number_sign();
	_number_sign_s();
	if (usign) {
		*--sp = '-';
		_hold();
	}
	_number_sign_greater();
	if (sp[0] < r) {
		sp--;
		sp[0] = r - sp[1];
		_spaces();
	}
	_type();
	putchar(' ');
}

void _d_zero_less() {
	register DCell d = GET_DCELL(sp);
	sp++;
	sp[0] = FFLAG(d < 0);
}

void _d_zero_equals() {
	register DCell d = GET_DCELL(sp);
	sp++;
	sp[0] = FFLAG(d == 0);
}

void _d_two_star() {
	register DCell d = GET_DCELL(sp);
	d <<= 1;
	PUT_DCELL(sp, d);
}

void _d_two_slash() {
	register DCell d = GET_DCELL(sp);
	d >>= 1;
	PUT_DCELL(sp, d);
}

void _d_less_than() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	sp += 3;
	sp[0] = FFLAG(d1 < d2);
}

void _d_equals() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	sp += 3;
	sp[0] = FFLAG(d1 == d2);
}

void _dabs() {
	register DCell d = GET_DCELL(sp);
	d = d > 0 ? d : -d;
	PUT_DCELL(sp, d);
}

void _dmax() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	sp += 2;
	if (d2 > d1) PUT_DCELL(sp, d2);
}

void _dmin() {
	register DCell d1 = GET_DCELL(sp + 2);
	register DCell d2 = GET_DCELL(sp);
	sp += 2;
	if (d2 < d1) PUT_DCELL(sp, d2);
}

void _dnegate() {
	register DCell d = -GET_DCELL(sp);
	PUT_DCELL(sp, d);
}

void _m_star_slash() {
	register Cell n2 = *sp++;
	register Cell n1 = *sp++;
	register DCell d = GET_DCELL(sp);
	d = (d * n1) / n2;
	PUT_DCELL(sp, d);
}

void _m_plus() {
	_s_to_d();
	_d_plus();
}