ldecNumber

Check-in [90090ab04d]
Login

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

Overview
Comment:Fix setdefault(INIT_BASE) to clear traps. Document that. Add some tests of divide by zero. Remove .xtml file from distro.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:90090ab04d9a0e400b6634884f1d02bda553250b
User & Date: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc 2006-09-25 00:48:58
Context
2006-09-25
14:43
Fix bug in mod for zero remainder, update tests and doco. Tweak makefile. check-in: 3eab477814 user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
00:48
Fix setdefault(INIT_BASE) to clear traps. Document that. Add some tests of divide by zero. Remove .xtml file from distro. check-in: 90090ab04d user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
2006-09-24
22:09
Add mod (%) function, operator, tests, and doco. check-in: 78e9b442c1 user: e@6e5be3b1-1950-f047-a965-c680c9cf6ecc tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#T= $(MYLIB).so
T= $(MYLIB).dll

TESTLIBS=test/lperformance.DLL

all: $T

$T:	$(OBJS) version.h
	$(CC) $(SHFLAGS) -o $@ -shared $(OBJS) $(LIBS)

$(MYLIB).o: version.h

version.h: vcheck

vcheck:
................................................................................
	echo 'Exporting...'
	mkdir -p $(TMP)
	mkdir -p $(DISTDIR)
	svn export -r HEAD . $(TMP)/$(MYLIB)-$(VER)
	cp -p version.h $(TMP)/$(MYLIB)-$(VER)
	cp -p doc/decNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc
	cp -p doc/ldecNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc
	cp -p doc/ldecNumber.xhtml $(TMP)/$(MYLIB)-$(VER)/doc
	echo 'Compressing...'
	tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
	rm -fr $(TMP)/$(MYLIB)-$(VER)
	echo 'Done.'

.PHONY: all vcheck test testall clean td dist install







|







 







<






34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
74
75
76
77
78
79
80

81
82
83
84
85
86
#T= $(MYLIB).so
T= $(MYLIB).dll

TESTLIBS=test/lperformance.DLL

all: $T

$T:	$(OBJS)
	$(CC) $(SHFLAGS) -o $@ -shared $(OBJS) $(LIBS)

$(MYLIB).o: version.h

version.h: vcheck

vcheck:
................................................................................
	echo 'Exporting...'
	mkdir -p $(TMP)
	mkdir -p $(DISTDIR)
	svn export -r HEAD . $(TMP)/$(MYLIB)-$(VER)
	cp -p version.h $(TMP)/$(MYLIB)-$(VER)
	cp -p doc/decNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc
	cp -p doc/ldecNumber.pdf $(TMP)/$(MYLIB)-$(VER)/doc

	echo 'Compressing...'
	tar -zcf $(TARFILE) -C $(TMP) $(MYLIB)-$(VER)
	rm -fr $(TMP)/$(MYLIB)-$(VER)
	echo 'Done.'

.PHONY: all vcheck test testall clean td dist install

Changes to doc/ldecNumber.odt.

cannot compute difference between binary files

Changes to ldecNumber.c.

328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
...
453
454
455
456
457
458
459




460
461
462
463
464
465
466
static int dn_mod (lua_State *L)
{
    decContext *dc = ldn_get_context (L);
    decNumber *dn1 = ldn_get (L, dc, 1);
    decNumber *dn2 = ldn_get (L, dc, 2);
    decNumber *dnr = ldn_make_decNumber (L);
    decNumberRemainder (dnr, dn1, dn2, dc);
    if ((decNumberIsNegative(dn1) ^ decNumberIsNegative(dn2)) != 0)
    {
        // convert remainder to modulo for mismatched signs
        decNumberAdd (dnr, dnr, dn2, dc);
    }
    return 1;
}

................................................................................
    if (   kind == DEC_INIT_DECIMAL128
        || kind == DEC_INIT_DECIMAL64
        || kind == DEC_INIT_DECIMAL32
        || kind == DEC_INIT_BASE
       )
    {
        decContextDefault (dc, kind);




    }
    else
    {
        luaL_error (L, "arg out of range for decNumber default");
    }
    return 0;
}







|







 







>
>
>
>







328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
...
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
static int dn_mod (lua_State *L)
{
    decContext *dc = ldn_get_context (L);
    decNumber *dn1 = ldn_get (L, dc, 1);
    decNumber *dn2 = ldn_get (L, dc, 2);
    decNumber *dnr = ldn_make_decNumber (L);
    decNumberRemainder (dnr, dn1, dn2, dc);
    if (decNumberIsNegative(dn1) != decNumberIsNegative(dn2))
    {
        // convert remainder to modulo for mismatched signs
        decNumberAdd (dnr, dnr, dn2, dc);
    }
    return 1;
}

................................................................................
    if (   kind == DEC_INIT_DECIMAL128
        || kind == DEC_INIT_DECIMAL64
        || kind == DEC_INIT_DECIMAL32
        || kind == DEC_INIT_BASE
       )
    {
        decContextDefault (dc, kind);
        if (kind == DEC_INIT_BASE)
        {
            dc->traps = 0; /* but turn off traps */
        }
    }
    else
    {
        luaL_error (L, "arg out of range for decNumber default");
    }
    return 0;
}

Changes to test/ldecNumberUnitTest.lua.

107
108
109
110
111
112
113






114
115
116

117
118
119
120
121









122
123
124
125
126
127
128
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
...
202
203
204
205
206
207
208

209
210
211
212
213









214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
...
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
local mod_funcs = lunit.TestCase("Floor/Mod Functions")

local function assert_qequal(x,y,...)
    local pass = (x-y):abs() < (decNumber.tonumber "0.0001")
    if not pass then print (x:tostring(),y:tostring()) end
    return assert_true(pass, ...)
end







function mod_funcs:test()
    local one = decNumber.tonumber "1"

    local a,b,x,y
    ctx = decNumber.getcontext()
    ctx:setdefault (decNumber.INIT_BASE)
    ctx:setdigits (69)
    ctx:setround (decNumber.ROUND_FLOOR)









    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
................................................................................
        assert_equal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_equal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_equal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_equal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)
        y = math.random(999999999)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_equal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_equal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_equal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_equal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_FLOOR)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_qequal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_qequal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_qequal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_qequal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
        y = math.random(999999999)/2^math.random(99)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_qequal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_qequal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
end

function mod_funcs:testinfix()
    local one = decNumber.tonumber "1"

    local a,b,x,y
    ctx = decNumber.getcontext()
    ctx:setdefault (decNumber.INIT_BASE)
    ctx:setdigits (69)
    ctx:setround (decNumber.ROUND_FLOOR)









    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
................................................................................
        assert_equal (a%b,decNumber.tonumber(x%y))
        assert_equal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_equal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_equal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)
        y = math.random(999999999)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_equal (a%b,decNumber.tonumber(x%y))
        assert_equal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_equal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_equal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_FLOOR)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
        y = math.random(999999999)/2^math.random(99)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_qequal (a%b,decNumber.tonumber(x%y))
        assert_qequal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_qequal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_qequal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)







>
>
>
>
>
>



>





>
>
>
>
>
>
>
>
>







 







|
|
|
|
|







 







|







 







|
|
|
|
|
|







 







>





>
>
>
>
>
>
>
>
>







 







|
|
|
|
|







 







|
|
|
|
|
|







 







|







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
...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
local mod_funcs = lunit.TestCase("Floor/Mod Functions")

local function assert_qequal(x,y,...)
    local pass = (x-y):abs() < (decNumber.tonumber "0.0001")
    if not pass then print (x:tostring(),y:tostring()) end
    return assert_true(pass, ...)
end

local function assert_nequal(x,y,...)
    local pass = x:isnan() and y:isnan() or x == y
    if not pass then print (x:tostring(),y:tostring()) end
    return assert_true(pass, ...)
end

function mod_funcs:test()
    local one = decNumber.tonumber "1"
    local zero = decNumber.tonumber "0"
    local a,b,x,y
    ctx = decNumber.getcontext()
    ctx:setdefault (decNumber.INIT_BASE)
    ctx:setdigits (69)
    ctx:setround (decNumber.ROUND_FLOOR)
    -- exceptions
    assert_true (zero:divide(zero):isnan())
    assert_true (zero:divideinteger(zero):isnan())
    assert_true (zero:remainder(zero):isnan())
    assert_true (zero:remaindernear(zero):isnan())
    assert_true (one:divide(zero):isinfinite())
    assert_true (one:divideinteger(zero):isinfinite())
    assert_true (one:remainder(zero):isnan())
    assert_true (one:remaindernear(zero):isnan())
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
................................................................................
        assert_equal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_equal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_equal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_equal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = zero
    assert_nequal (a:remainder(b),a - b * a:divideinteger(b))
    assert_nequal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_nequal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_nequal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)
        y = math.random(999999999)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_equal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_equal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_equal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_equal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_FLOOR)
    a = zero
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_qequal (decNumber.mod(a,b),decNumber.tonumber(x%y))
        assert_qequal (decNumber.mod(-a,b),decNumber.tonumber((-x)%y))
        assert_qequal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_qequal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = zero
    b = zero
    assert_nequal (a:remainder(b),a - b * a:divideinteger(b))
    assert_nequal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_nequal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_nequal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
        y = math.random(999999999)/2^math.random(99)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_qequal (decNumber.mod(a,-b),decNumber.tonumber(x%(-y)))
        assert_qequal (decNumber.mod(-a,-b),decNumber.tonumber((-x)%(-y)))
    end
end

function mod_funcs:testinfix()
    local one = decNumber.tonumber "1"
    local zero = decNumber.tonumber "0"
    local a,b,x,y
    ctx = decNumber.getcontext()
    ctx:setdefault (decNumber.INIT_BASE)
    ctx:setdigits (69)
    ctx:setround (decNumber.ROUND_FLOOR)
    -- exceptions
    assert_true (zero:divide(zero):isnan())
    assert_true (zero:divideinteger(zero):isnan())
    assert_true (zero:remainder(zero):isnan())
    assert_true (zero:remaindernear(zero):isnan())
    assert_true (one:divide(zero):isinfinite())
    assert_true (one:divideinteger(zero):isinfinite())
    assert_true (one:remainder(zero):isnan())
    assert_true (one:remaindernear(zero):isnan())
    a = one
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
................................................................................
        assert_equal (a%b,decNumber.tonumber(x%y))
        assert_equal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_equal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_equal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = one
    b = zero
    assert_nequal (a:remainder(b),a - b * a:divideinteger(b))
    assert_nequal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_nequal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_nequal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)
        y = math.random(999999999)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_equal (a%b,decNumber.tonumber(x%y))
        assert_equal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_equal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_equal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_FLOOR)
    a = zero
    b = zero
    assert_nequal (a:remainder(b),a - b * a:divideinteger(b))
    assert_nequal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_nequal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_nequal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)
        y = math.random(999999999)/2^math.random(99)
        a = decNumber.tonumber(x)
        b = decNumber.tonumber(y)
        assert_equal (a:remainder(b),a - b * a:divideinteger(b))
        assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
................................................................................
        assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
        assert_qequal (a%b,decNumber.tonumber(x%y))
        assert_qequal ((-a)%b,decNumber.tonumber((-x)%y))
        assert_qequal (a%(-b),decNumber.tonumber(x%(-y)))
        assert_qequal ((-a)%(-b),decNumber.tonumber((-x)%(-y)))
    end
    ctx:setround (decNumber.ROUND_CEILING)
    a = zero
    b = one
    assert_equal (a:remainder(b),a - b * a:divideinteger(b))
    assert_equal ((-a):remainder(b),(-a) - b * (-a):divideinteger(b))
    assert_equal (a:remainder(-b),a + b * a:divideinteger(-b))
    assert_equal ((-a):remainder(-b),(-a) + b * (-a):divideinteger(-b))
    for i = 1,100 do
        x = math.random(999999999)/2^math.random(99)