R Under development (unstable) (2025-02-12 r87715 ucrt) -- "Unsuffered Consequences" Copyright (C) 2025 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(flint) > flint:::.initBasic() > > > ## Test that as(, "") and as.() work correctly > ## for all 'flint' subclasses and all basic vector types . > ## Use 0 and 1 as test cases as these are in the range of every class. > ## Allow for imprecision in "mag" conversions which are not exact even > ## in exactly representable cases. > > cl <- c("ulong", "slong", "fmpz", "fmpq", "mag", "arf", "acf", + "arb", "acb") > cl.complexlike <- cl == "acf" | cl == "acb" > basic <- c("raw", "logical", "integer", "double", "numeric", "complex", + "vector") > zu <- lapply(cl, function (s) new(s, x = c(0, 1))) > for (t in basic) { + as. <- match.fun(paste0("as.", t)) + as.01 <- list(as.(c(0, 1)), as.(c(0, 1)+0i))[1L + cl.complexlike] + as.zu <- lapply(zu, as, t); as.zu. <- lapply(zu, as.) + stopifnot(identical(as.zu, as.zu.), + identical(as.zu[-5L], as.01[-5L]), + all.equal(as.zu[ 5L], as.01[ 5L])) + } > > > ## Test that typeof(as.vector(.)) is "complex" for 'acf', 'acb' > ## and "double" otherwise. > > stopifnot(identical(vapply(lapply(zu, as.vector), typeof, ""), + c("double", "complex")[1L + cl.complexlike])) > > > ## Test that exactly one condition (a warning) is signaled when > ## nonzero imaginary parts are discarded and that no condition is > ## signaled otherwise. > > zi <- .acb(x = 0i) > ui <- .acb(x = 1i) > tools::assertError(tools::assertCondition(zi.c <- as.complex(zi))) > tools::assertError(tools::assertCondition(zi.d <- as.double (zi))) > tools::assertError(tools::assertCondition(ui.c <- as.complex(ui))) > aw <- tools::assertWarning (ui.d <- as.double (ui)) > stopifnot(length(aw) == 1L, + identical(zi.c, 0i), + identical(zi.d, 0), + identical(ui.c, 1i), + identical(ui.d, 0)) > > proc.time() user system elapsed 0.45 0.06 0.50