|
256 | 256 | @test varm(a, m) === varm(af, m) |
257 | 257 | end |
258 | 258 |
|
259 | | -@testset "convert result type" begin |
260 | | - x = Fixed{Int8,7}(0.75) |
261 | | - for T in (Float16, Float32, Float64, BigFloat) |
262 | | - y = convert(T, x) |
263 | | - @test isa(y, T) |
264 | | - end |
265 | | -end |
266 | | - |
267 | 259 | @testset "bool conversions" begin |
268 | 260 | @test convert(Bool, 0.0Q1f6) === false |
269 | 261 | @test convert(Bool, 1.0Q1f6) === true |
|
272 | 264 | @test_broken convert(Bool, Fixed{Int8,8}(0.2)) # TODO: remove this |
273 | 265 | end |
274 | 266 |
|
275 | | -@testset "Integer conversions" begin |
| 267 | +@testset "integer conversions" begin |
276 | 268 | @test convert(Int, Q1f6(1)) === 1 |
277 | 269 | @test convert(Integer, Q1f6(1)) === Int8(1) |
278 | 270 | @test convert(UInt, 1Q1f6) === UInt(1) |
|
283 | 275 | @testset "rational conversions" begin |
284 | 276 | @test convert(Rational, -0.75Q1f6) === Rational{Int8}(-3//4) |
285 | 277 | @test convert(Rational, -0.75Q0f7) === Rational{Int16}(-3//4) |
286 | | - @test convert(Rational{Int}, -0.75Q0f7) === Rational(-3//4) |
| 278 | + @test convert(Rational{Int}, -0.75Q0f7) === Rational{Int}(-3//4) |
| 279 | + |
| 280 | + @test rationalize(-0.75Q3f4) === Rational{Int}(-3//4) |
| 281 | + @test rationalize(Int16, 0.81Q3f4) === Rational{Int16}(13//16) |
| 282 | + @test rationalize(-0.81Q3f4, tol=0.02) === Rational{Int}(-13//16) |
| 283 | + @test rationalize(Int8, -0.81Q3f4, tol=0.07) === Rational{Int8}(-3//4) |
| 284 | +end |
| 285 | + |
| 286 | +@testset "BigFloat conversions" begin |
| 287 | + @test convert(BigFloat, -0.75Q0f7)::BigFloat == big"-0.75" |
| 288 | + |
| 289 | + @test big(Q7f0) === BigFloat # !== BigInt |
| 290 | + @test big(0.75Q3f4)::BigFloat == big"0.75" |
287 | 291 | end |
288 | 292 |
|
289 | 293 | @testset "Floating-point conversions" begin |
|
293 | 297 | end |
294 | 298 |
|
295 | 299 | @testset "conversions to float" begin |
296 | | - for T in (Float16, Float32, Float64, BigFloat) |
| 300 | + for T in (Float16, Float32, Float64) |
297 | 301 | @test isa(convert(T, Q0f7(0.3)), T) |
298 | 302 | end |
299 | 303 |
|
|
0 commit comments