Skip to content
Prev 325798 / 398503 Next

Built-in function for extracting mantissa and exponent of a numeric

Hello,

Sorry I forgot to Cc the list.
And I had forgotten the case where x == 0.


extract <- function(x){
	e <- ifelse(x == 0, 0, floor(log10(x)))
	m <- x/10^e
	list(mantissa = m, exponent = e)
}

extract(c(0, 1.234e12, 12345678901234, 123e123))


Hope this helps,

Rui Barradas

Em 23-06-2013 10:54, S?ren H?jsgaard escreveu: