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