# Program Listings Desktop Computing Power         techBASIC brings the power of a desktop computer to your iPhone/iPad for programming, collecting and analyzing data, and visualizing and manipulating stunning 3D graphics. It’s a full implementation of the famously easy to use BASIC Programming Language with specialized array and matrix commands built in.

During the time I was learning and developing programs in SmartBASIC, I ran into problems when working on papers and research in my cosmology fields. If I tried to expand the exponent of the mass of the Sun, for example, 2*10^30, I should get 2 followed by 30 zeroes/

Instead, in SmartBASIC, as is in the language it is written in, C/C++, it uses the 8-11-53 mantassia method of precision for all number less than 2^53-1, or 9,007,199,254,740,992 (or just more than 9 Quadrillion).

For most business applications, this is perfectly fine. Our currency is based on the debt sytem, according to the Federal Reserve’s own document, and we are \$20 trillion in debt today (as of Jan 25, 2017). That is 2 followed by 12 zeroes, well within the precision computational powers of SmartBASIC.

What happens when you need to calculate the temperature of a black hole 30 times the mass of the Sun, or (2*10^30)*30?

First, when you convert in SmartBASIC your exponent of 2E+30 into a long string, you expect to see 2,000,000,000,000,000,000,000,000,000,000 ( or 2 Nonillion). But SmartBASIC, since it only represents numbers upt to 2^53 with precision, you get: 2,000,000,000,000,000,039,769,249,677,312. Where did 39,769,249,677,312 come from? They are all supposed to be zeroes. All I did was expand the exponent into a long string.

I was told that the mantissa was only accurate to seven numbers, and that the rest was due to the unprecise way SmarBASIC, or C/C++ or the hardware math chip handles large numbers.

So in looking for an alternative, I, with the help of a frield, found techBASIC, and I was hooked when a scientist said it worked great with large numbers and it is calculus ready. so I decided to do a small experiment, as I never worked with a programming language that had such a low threshold for precision numbers, and all my calculations were wrong!

Below is the source code I wrote in “R” that I use to validate a programming language ‘s ability to  handle large numbers. I duplicate the code from my “R” program into the language that I’m testing so that I can compare like values and computational results.

## “R” Code Listing:

```### Numeric Precision and Accuracy Testing
### This program takes the information about the product's capabilities and puts them
### through a series of test cases, some designed to verify the accuracy of the precision
### claimed, and even tries to break and exceed their specifications to better understand
### how the language calculates, stores and what is actually being used in calculations.
###
### For example, this program stretches out an exponent's mantissa and found that a simple
### 2*10^30 produced more than a 2 followed by 30 zeroes. Was that caused by the way the
### number was printed?
###
### To answer this and other questions like it, all results from other languages and machines
### are stored, even the worksheets of my brute-force math to prove or disprove whether the
### issue is software or hardware, or even limits imposed by the developer of the language itself.

### The following tests have numbers (proofs) to validate the precision of a language or hardware
### Math Processors. In this case, the "R" Programming Language is being used as both a proof and
### as a testcase of its own number precision capabilities, or lack there of.

## use of format Function and scientific parameter
format(2^52)
format(2^52, scientific = TRUE)
format(2^53)
format(2^53, scientific = TRUE)

## use of toString Function
toString(2^52, width=18)
toString(2^53, width=18)
toString(2*10^30, width=31)

## use of calculating mass of the Sun in exponents, format function scientific parameters
format(2*10^30)
format(2*10^30, scientific = TRUE)

## C-format function with scientific and double precision parameters
formatC(2e30, format="f", mode="double", dig=NULL)  # The mass of the Sun 2 + 30 zeroe's
format(2e30, digits=NULL, big.mark=",", scientific=TRUE)

## prettyNum vs. the C-Format Functions (formatC set for 80 digits)
r > also long strings

#### Additional Stress Testing Cases follow
### Load a list with some rather large numbers and process them as strings
xx > also long strings

#### Below are all the functions that are called (commented out so we call the library versions)
#### These are provided so the programmer can see all the parameters they can set to do testing.
#### Functions include: format, toString, formatC and prettyNum/
## Default S3 method:
#format(x, trim = FALSE, digits = NULL, nsmall = 0,
#       justify = c("left", "right", "centre", "none"),
#       width = NULL, na.encode = TRUE, scientific = NA,
#       big.mark = "",   big.interval = 3,
#     small.mark = "", small.interval = 5,
#   decimal.mark = ".", zero.print = NULL, ...)

## Default S3 method:
#toString(x, width = NULL, ...)
### Functions commented out below to view all parameters
#formatC(x, digits = NULL, width = NULL,
#        format = NULL, flag = "", mode = NULL,
#        big.mark = "", big.interval = 3,
#      small.mark = "", small.interval = 5,
#    decimal.mark = ".", preserve.width = "individual")

#prettyNum(x, big.mark = "",   big.interval = 3,
#          small.mark = "", small.interval = 5,
#          decimal.mark = ".",
#          preserve.width = c("common", "individual", "none"),
#          zero.print = NULL, ...)
```

## “R” Code Results:

``` "4.5036e+15"
 "4.5036e+15"
 "9.007199e+15"
 "9.007199e+15"
 "4503599627370496"
 "9007199254740992"
 "2e+30"
 "2e+30"
 "2e+30"
 "2000000000000000039769249677312.0000"
 "2e+30"
 "2,000,000,000,000,000,000,000,000,000,000"
 "2000000000000000039769249677312.00000000000000000000000000000000000000000000000000000000000000000000000000000000"
 "1e-12"      "-3.988e-10" "1.456e-69"  "1e-70"      "3.142e+37"
 "3.44e+04"
 "0.000000000001"
 "-0.0000000003988"
 "0.000000000000000000000000000000000000000000000000000000000000000000001456"
 "0.0000000000000000000000000000000000000000000000000000000000000000000001"
 "31415926535897927981986333033020522496"
 "34400"
 "0.00000000000099999999999999997988664762925561536725284350612952266601496376097202"
 "-0.00000000039876500000000001832063751804080022067555688636275590397417545318603516"
 "0.00000000000000000000000000000000000000000000000000000000000000000000145645000000"
 "0.00000000000000000000000000000000000000000000000000000000000000000000010000000000"
 "31415926535897927981986333033020522496.00000000000000000000000000000000000000000000000000000000000000000000000000000000"
 "34400.00000000000000000000000000000000000000000000000000000000000000000000000000000000"
```