R: Integer truncation of logb output

ilogb {ifultools} | R Documentation

## Integer truncation of logb output

### Description

Calculates `logb(x, base=base) + eps` where `eps` is a user-supplied (small) value and converts the result ala `as.integer`. The purpose of this function is to avoid `logb` variations between platforms. As an example, it is conceivable that `logb(32, base=2)` on one platform could return a value of `5` while on another platform it could return a slightly smaller value, e.g., `4.999999999999999`. The difference is due to different compiler and platform-specific implementations of the S-PLUS or R languages. If `logb` output is truncated (as is the case with `as.integer(logb(x))`) then the result may be unexpected, leading to intractable errors. By adding an appropriate and small value to `logb(x)`, subsequent truncation results in consistent value(s) across platforms.

### Usage

    ilogb(x, base=2, eps=.Machine$double.eps * 1e9)

### Arguments

`x` | a numeric or complex vector.
`base` | a positive or complex number: the base with respect to which logarithms are computed. Default: `2`.
`eps` | a small numeric value that is added to the `logb` result prior to truncation via `as.integer`. Default: `.Machine\$double.eps * 1e9`.

### Value

a numeric scalar or vector containing the result.

### See Also

`logScale`.

### Examples

    ## should return 3
    ilogb(8 - .Machine$double.eps, base=2)

[Package ifultools version 2.0-19 Index]