@@ -247,22 +247,97 @@ end
247247end
248248
249249@testset " round" begin
250- @test round (11 // 2 ) == 6 // 1 # rounds to closest _even_ integer
251- @test round (- 11 // 2 ) == - 6 // 1 # rounds to closest _even_ integer
252- @test round (11 // 3 ) == 4 // 1 # rounds to closest _even_ integer
253- @test round (- 11 // 3 ) == - 4 // 1 # rounds to closest _even_ integer
250+ @test round (11 // 2 ) == round (11 // 2 , RoundNearest) == 6 // 1 # rounds to closest _even_ integer
251+ @test round (- 11 // 2 ) == round (- 11 // 2 , RoundNearest) == - 6 // 1 # rounds to closest _even_ integer
252+ @test round (13 // 2 ) == round (13 // 2 , RoundNearest) == 6 // 1 # rounds to closest _even_ integer
253+ @test round (- 13 // 2 ) == round (- 13 // 2 , RoundNearest) == - 6 // 1 # rounds to closest _even_ integer
254+ @test round (11 // 3 ) == round (11 // 3 , RoundNearest) == 4 // 1 # rounds to closest _even_ integer
255+ @test round (- 11 // 3 ) == round (- 11 // 3 , RoundNearest) == - 4 // 1 # rounds to closest _even_ integer
256+
257+ @test round (11 // 2 , RoundNearestTiesAway) == 6 // 1
258+ @test round (- 11 // 2 , RoundNearestTiesAway) == - 6 // 1
259+ @test round (13 // 2 , RoundNearestTiesAway) == 7 // 1
260+ @test round (- 13 // 2 , RoundNearestTiesAway) == - 7 // 1
261+ @test round (11 // 3 , RoundNearestTiesAway) == 4 // 1
262+ @test round (- 11 // 3 , RoundNearestTiesAway) == - 4 // 1
263+
264+ @test round (11 // 2 , RoundNearestTiesUp) == 6 // 1
265+ @test round (- 11 // 2 , RoundNearestTiesUp) == - 5 // 1
266+ @test round (13 // 2 , RoundNearestTiesUp) == 7 // 1
267+ @test round (- 13 // 2 , RoundNearestTiesUp) == - 6 // 1
268+ @test round (11 // 3 , RoundNearestTiesUp) == 4 // 1
269+ @test round (- 11 // 3 , RoundNearestTiesUp) == - 4 // 1
270+
271+ @test trunc (11 // 2 ) == round (11 // 2 , RoundToZero) == 5 // 1
272+ @test trunc (- 11 // 2 ) == round (- 11 // 2 , RoundToZero) == - 5 // 1
273+ @test trunc (13 // 2 ) == round (13 // 2 , RoundToZero) == 6 // 1
274+ @test trunc (- 13 // 2 ) == round (- 13 // 2 , RoundToZero) == - 6 // 1
275+ @test trunc (11 // 3 ) == round (11 // 3 , RoundToZero) == 3 // 1
276+ @test trunc (- 11 // 3 ) == round (- 11 // 3 , RoundToZero) == - 3 // 1
277+
278+ @test ceil (11 // 2 ) == round (11 // 2 , RoundUp) == 6 // 1
279+ @test ceil (- 11 // 2 ) == round (- 11 // 2 , RoundUp) == - 5 // 1
280+ @test ceil (13 // 2 ) == round (13 // 2 , RoundUp) == 7 // 1
281+ @test ceil (- 13 // 2 ) == round (- 13 // 2 , RoundUp) == - 6 // 1
282+ @test ceil (11 // 3 ) == round (11 // 3 , RoundUp) == 4 // 1
283+ @test ceil (- 11 // 3 ) == round (- 11 // 3 , RoundUp) == - 3 // 1
284+
285+ @test floor (11 // 2 ) == round (11 // 2 , RoundDown) == 5 // 1
286+ @test floor (- 11 // 2 ) == round (- 11 // 2 , RoundDown) == - 6 // 1
287+ @test floor (13 // 2 ) == round (13 // 2 , RoundDown) == 6 // 1
288+ @test floor (- 13 // 2 ) == round (- 13 // 2 , RoundDown) == - 7 // 1
289+ @test floor (11 // 3 ) == round (11 // 3 , RoundDown) == 3 // 1
290+ @test floor (- 11 // 3 ) == round (- 11 // 3 , RoundDown) == - 4 // 1
254291
255292 for T in (Float16, Float32, Float64)
256293 @test round (T, true // false ) === convert (T, Inf )
257294 @test round (T, true // true ) === one (T)
258295 @test round (T, false // true ) === zero (T)
296+ @test trunc (T, true // false ) === convert (T, Inf )
297+ @test trunc (T, true // true ) === one (T)
298+ @test trunc (T, false // true ) === zero (T)
299+ @test floor (T, true // false ) === convert (T, Inf )
300+ @test floor (T, true // true ) === one (T)
301+ @test floor (T, false // true ) === zero (T)
302+ @test ceil (T, true // false ) === convert (T, Inf )
303+ @test ceil (T, true // true ) === one (T)
304+ @test ceil (T, false // true ) === zero (T)
259305 end
260306
261307 for T in (Int8, Int16, Int32, Int64, Bool)
262308 @test_throws DivideError round (T, true // false )
263309 @test round (T, true // true ) === one (T)
264310 @test round (T, false // true ) === zero (T)
311+ @test_throws DivideError trunc (T, true // false )
312+ @test trunc (T, true // true ) === one (T)
313+ @test trunc (T, false // true ) === zero (T)
314+ @test_throws DivideError floor (T, true // false )
315+ @test floor (T, true // true ) === one (T)
316+ @test floor (T, false // true ) === zero (T)
317+ @test_throws DivideError ceil (T, true // false )
318+ @test ceil (T, true // true ) === one (T)
319+ @test ceil (T, false // true ) === zero (T)
265320 end
321+
322+ # issue 34657
323+ @test round (1 // 0 ) === round (Rational, 1 // 0 ) === 1 // 0
324+ @test trunc (1 // 0 ) === trunc (Rational, 1 // 0 ) === 1 // 0
325+ @test floor (1 // 0 ) === floor (Rational, 1 // 0 ) === 1 // 0
326+ @test ceil (1 // 0 ) === ceil (Rational, 1 // 0 ) === 1 // 0
327+ @test round (- 1 // 0 ) === round (Rational, - 1 // 0 ) === - 1 // 0
328+ @test trunc (- 1 // 0 ) === trunc (Rational, - 1 // 0 ) === - 1 // 0
329+ @test floor (- 1 // 0 ) === floor (Rational, - 1 // 0 ) === - 1 // 0
330+ @test ceil (- 1 // 0 ) === ceil (Rational, - 1 // 0 ) === - 1 // 0
331+ for r = [RoundNearest, RoundNearestTiesAway, RoundNearestTiesUp,
332+ RoundToZero, RoundUp, RoundDown]
333+ @test round (1 // 0 , r) === 1 // 0
334+ @test round (- 1 // 0 , r) === - 1 // 0
335+ end
336+
337+ @test @inferred (round (1 // 0 , digits= 1 )) === Inf
338+ @test @inferred (trunc (1 // 0 , digits= 2 )) === Inf
339+ @test @inferred (floor (- 1 // 0 , sigdigits= 1 )) === - Inf
340+ @test @inferred (ceil (- 1 // 0 , sigdigits= 2 )) === - Inf
266341end
267342
268343@testset " issue 1552" begin
0 commit comments