[R] addition using binary

davidr at rhotrading.com davidr at rhotrading.com
Tue Mar 28 16:54:27 CEST 2006


Looks as if you are dealing with bond prices (or futures, which are
quoted in 32nds), and someone has been creative with the way they store
them.
I would convert them all to doubles (represented exactly in the
computer)
and just add directly. x <- floor(p) + (p-floor(p))*100/32 . Finally, if
you need to convert back, p <- floor(x) + (x-floor(x))*32/100 .

In general, I have found storing prices as rationals very useful in most
contexts, although as noted above, in many circumstances, doubles are
exact.

David L. Reiner
Rho Trading Securities, LLC
Chicago  IL  60605
312-362-4963

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Fred J.
Sent: Sunday, March 26, 2006 1:52 PM
To: r-help at stat.math.ethz.ch
Subject: [R] addition using binary

Dear R users
 
 I looked around for a package which can help me with the task of binary
arithmetic, the closest I found is sfsmisc with digitsBase function,
which may help a little in this task, but still wondering how to get
this problem solved.
 
 example:
 given the addition operation of 2 real numbers to equal as below
  99.30
    2.11
 ===
 102.09  <--- desired output as explained below
 
 the decimal point is for ease or reading and does carry the usual
meaning.
 
 the numbers t0 the right of the decimal point are added
 30
 11
 ===
 41
 divided by 32 equal 1 with a reminder of 9 
 
 the numbers to the left of the decimal point are added
 99
   2
 ===
 101
    1     which is carried from above
 ===
 102
 
 put together 102.09, again the decimal point doesn't carry the usual
meaning but only for ease of reading.
 the same principle above is needed to alse apply for other operations
like subtraction, 
 
 
 thank you
 
		
---------------------------------

	[[alternative HTML version deleted]]

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html




More information about the R-help mailing list