Description Usage Arguments Value Note Author(s) Examples
Functions for conversion of real to string and back, in given base, in fixed and exponential format; and rounding in base number system.
1 2 3 4 5 6 7 |
x |
Real or integer, vector |
STR |
Vector of strings representing reals in a given base |
base |
2 <= integer <= 60, base of representation |
space |
Integer, space for resulting string; |
rnd |
Integer, number of places (after ".") to be rounded; |
plus |
use "+" to show sign for positive values. |
lead |
use "" or " "; or "0" for leading zeros; this will be inserted after sign. |
just |
Choice of insertion of justification, can be abbreviated, see |
roundB
: vector of arguments rounded to rnd
places according to base base
representation
r2B
: list( s=vector of strings represention of x
, rounded to rnd
decimal digits, base=base)
r2Be
: like r2B
, but in exponential representation, if space
too small. The exponent marker is "e" for base==10
and EXPCHAR
otherwise.
strB2r
: real corresponding to string representation. NaN
is returned if str
contains characters not in HexagesDig[1:base]
(as are generated by r2B
, r2Be
).
strB2i
: integer ( str2i ) corresponding to string representation, used in strB2r
r2B(.)
and strB2(.)
are inverses of each other.
r2Be
chooses between fixed and exponential format depending on available space, adjusting rounding accordingly. just="left"
works best with lead
= "" = default.
strB2r
can convert strings with exponent signifyers "e"
(for decimals) and "z"
for others, "."
is allowed for fractional parts.
strB2i
works on strings without "e","z","."
ONLY!
Christian W. Hoffmann <christian@echoffmann.ch>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | x <- c(0,-0.0012345, 1.5234, 543, 8123456,NA,Inf,-Inf,NaN,1,pi)
y <- c( 0, 1, pi*10^c(-27,-8,0, 8) )
# "+3.1e27" " NA " " NaN " " Inf )
r2B(x,,space=10,lead=" ",plus="",rnd=3)$s
# " 0 " "- 0.001" " 1.523" " 543.000"
# " 8123456.000" " NA" " Inf" " -Inf"
# " NaN" " 1.000" " 3.142"
r2B(x,16,space=10,lead=" ")$s
# " 0 " "- 0" " 2" " 21F"
# " 7BF440" " NA" " Inf"" -Inf"
# " NaN" " 1" " 3"
r2B( x, 60, 4 )$s
r2Be( y,10,7)$s
# " 0 " "+1.0000" "+3.e-27" "+3.1e-8" "+3.1416" "+3.14e8"
# "+3.1e27" " NA " " NaN " " Inf "
strB2r("- 9167.8 4",10)
strB2r("B00z3",15 ) # 8353125
(ii <- r2B( 8353125, 32, 4 )$s) # "7UTB5.0000"
strB2r( ii, 32) # 8353125
roundB(c(0.4,0.3),2,16) # 0.39999390 0.30000305
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.