In order to have exact geometric computations it is necessary to avoid the issues of floating point arithmetic. CGAL can work with a range of different exact kernels, where euclid uses the Exact_predicates_exact_constructions predifined kernel. Moving values in and out of R would force a conversion to double thus destroying the exactness of computation, so euclid provides a new numeric vector class that simply maps to the underlying exact representation. While the exact numeric class generally behaves as a standard numeric there are operations that are not possible because it will loose the exactness, e.g. trigonometric functions, roots, etc. If any unsupported function is needed it is necessary to convert back to numeric (thus loosing exactness). Anywhere euclid takes a numeric input it will convert it to an exact numeric before use.

exact_numeric(x = numeric(0))

is_exact_numeric(x)

as_exact_numeric(x)

## Arguments

x An object coercible to numeric

## Value

An euclid_exact_numeric vector

## Note

Exact numeric only have one form of non-finite value: NA. Any other non-finite value will be converted to that.

## Examples

# Standard use
exact_numeric(runif(5))
#> <exact numerics >
#>  0.85438389 0.21314931 0.21031074 0.03952069 0.94477480
# Non-finite numbers are all converted to NA
exact_numeric(NaN)
#> <exact numerics >
#>  NA
# this is also true for division by zero
exact_numeric(runif(5)) / 0
#> <exact numerics >
#>  NA NA NA NA NA
# Exact numerics are more limited on operations but doesn't have the
# weirdness of floating point arithmetic:
float <- c(1, 2, 3)
identical(float + float, float)
#>  TRUEfloat <- float / 10
identical((float + float) * 10, float * 10)
#>  FALSE
exact <- exact_numeric(c(1, 2, 3))
identical(as.numeric(exact + exact), as.numeric(exact))
#>  TRUEexact <- exact / 10
identical(as.numeric((exact + exact) * 10), as.numeric(exact * 10))
#>  TRUE
# This only holds if the input are exact to begin with
identical(
as.numeric(exact_numeric(1/10 + 2/10)),
as.numeric(exact_numeric(3/10))
)
#>  FALSE