Code covered by the BSD License

# HPF - a big decimal class

04 May 2012 (Updated )

High precision floating point arithmetic, a new class written in MATLAB

hpf_regression_testing

## Validation/regression tests

This is NOT a variety of regression/least squares tool. In fact, it has nothing to do with those capabilities of MATLAB. Instead, this document provides tests for each method in the HPF world, so that any bugs in future changes/enhancements to HPF will be efficiently caught. Each method in HPF is included, with a set of tests chosen specifically for that method to exercise the numerical precision and behavior of the method. Special cases are tested, such as the behavior of each function on empty arrays, inf, nan, etc. to conform to the expected behavior in MATLAB.

As a user, you can publish this file yourself on your own system, to then verify that all tests return the expected values.

Author: John D'Errico e-mail: woodchips@rochester.rr.com

```format long g
```

Save the current state to restore it later on

```OriginalDecimalBase = DefaultDecimalBase;
OriginalNDig = DefaultNumberOfDigits;

% Set the default digits to [64 4]
DefaultNumberOfDigits 64 4
```

## abs: absolute value

empty begets empty

```abs(hpf([]))
```
```ans =
[]
```

Goals: 12.34567890 0 1.234 inf nan

```X = [hpf('-12.34567890'), hpf(0), hpf('1.234'), hpf(-inf), hpf(nan)];
abs(X)
```
```ans =
HPF element: (1,1)
12.3456789
HPF element: (1,2)
0
HPF element: (1,3)
1.234
HPF element: (1,4)
Inf
HPF element: (1,5)
NaN
```

## acos: inverse cosine

empty begets empty

```acos(hpf([]))
```
```ans =
[]
```

Goals: 0, 1/4, 1/2, 2/3, 1, nan nan nan

```X = [hpf(1), sqrt(hpf(2))/2, hpf(0), hpf(-0.5), hpf(-1), hpf(-inf), hpf(inf), hpf(nan)];
acos(X)/hpf('pi')
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
0.25
HPF element: (1,3)
0.5
HPF element: (1,4)
0.6666666666666666666666666666666666666666666666666666666666666667
HPF element: (1,5)
1
HPF element: (1,6)
NaN
HPF element: (1,7)
NaN
HPF element: (1,8)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(2*rand(1,25) - 1);
log10(max(abs(acos(x) - acos(double(x)))))
```
```ans =
-15.22820811669277795076040253726491006944668418960843287256059339
```

Sym comparison:

vpa(acos(sym('1/4')),100)

ans = 1.318116071652817965745664254646040469846390966590714716853548517413333142662083276902268670443043932

```acos(hpf('0.25',100))
```
```ans =
1.318116071652817965745664254646040469846390966590714716853548517413333142662083276902268670443043932
```

## acosd:

empty begets empty

```acosd(hpf([]))
```
```ans =
[]
```

Goals: 0, 1/4, 1/2, 2/3, 1, nan nan nan

```X = [hpf(1), sqrt(hpf(2))/2, hpf(0), hpf(-0.5), hpf(-1), hpf(-inf), hpf(inf), hpf(nan)];
acosd(X)/180
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
0.25
HPF element: (1,3)
0.5
HPF element: (1,4)
0.6666666666666666666666666666666666666666666666666666666666666667
HPF element: (1,5)
1
HPF element: (1,6)
NaN
HPF element: (1,7)
NaN
HPF element: (1,8)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -13

```x = hpf(2*rand(1,10) - 1,100);
log10(max(abs(acosd(x) - acosd(double(x)))))
```
```ans =
-13.46004972988907961477371771724073736265344198338528022561941792508964737445234958384833904161666730
```

## acosh:

empty begets empty

```acosh(hpf([]))
```
```ans =
[]
```

Goals: [0, inf, NaN]

```acosh(hpf([1 inf NaN],50))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
Inf
HPF element: (1,3)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(exp(2*rand(1,10)));
log10(max(abs(double(acosh(x)) - acosh(double(x)))))
```
```ans =
-14.8938919298374
```

Sym comparison:

vpa(acosh(sym(17)),100)

ans = 3.525494348078172100930437299919169236112641313046541643013182434613508736888104351334827567641024171

```acosh(hpf('17',100))
```
```ans =
3.525494348078172100930437299919169236112641313046541643013182434613508736888104351334827567641024171
```

## acot:

empty begets empty

```acot(hpf([]))
```
```ans =
[]
```

Goals: [pi/2, 0, 0, NaN]

```acot(hpf([0 -inf inf NaN],50))
```
```ans =
HPF element: (1,1)
1.5707963267948966192313216916397514420985846996876
HPF element: (1,2)
0
HPF element: (1,3)
0
HPF element: (1,4)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(10*rand(1,10)-5,50);
log10(max(abs(double(acot(x)) - acot(double(x)))))
```
```ans =
-15.4774685154713
```

Sym comparison:

vpa(acot(sym(17)),100)

ans = 0.05875582271572269290218330245177178547665041810044464614350256296744422042319255800245502374523156074

```acot(hpf('17',100))
```
```ans =
0.05875582271572269290218330245177178547665041810044464614350256296744422042319255800245502374523156074
```

## acsc:

empty begets empty

```acsc(hpf([]))
```
```ans =
[]
```

Goals: [-pi/2, pi/2, 0, 0, NaN]

```acsc(hpf([-1 1 -inf inf NaN],50))
```
```ans =
HPF element: (1,1)
-1.5707963267948966192313216916397514420985846996876
HPF element: (1,2)
1.5707963267948966192313216916397514420985846996876
HPF element: (1,3)
0
HPF element: (1,4)
0
HPF element: (1,5)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(5*rand(1,20).*(2*round(rand(1,20))-1),30);
log10(max(abs(double(acsc(x)) - acsc(double(x)))))
```
```ans =
-15.1764385198074
```

Sym comparison:

vpa(acsc(sym(17)),100)

ans = 0.05885750594708123021242193548567836102172841359730737506627786418916451737407051526190724208378293111

```acsc(hpf('17',100))
```
```ans =
0.05885750594708123021242193548567836102172841359730737506627786418916451737407051526190724208378293111
```

## asec

empty begets empty

```asec(hpf([]))
```
```ans =
[]
```

Goals: [pi, 0, pi/2, pi/2, NaN]

```asec(hpf([-1 1 -inf inf NaN],50))
```
```ans =
HPF element: (1,1)
3.1415926535897932384626433832795028841971693993751
HPF element: (1,2)
0
HPF element: (1,3)
1.5707963267948966192313216916397514420985846996876
HPF element: (1,4)
1.5707963267948966192313216916397514420985846996876
HPF element: (1,5)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(10*rand(1,10)-5,30);
log10(max(abs(double(asec(x)) - asec(double(x)))))
```
```ans =
-15.352529778863
```

Sym comparison:

vpa(asec(sym(17)),100)

ans = 1.511938820847815389018899756154073081076856286090245535421194431964743685769033984052110170587275603

```asec(hpf('17',100))
```
```ans =
1.511938820847815389018899756154073081076856286090245535421194431964743685769033984052110170587275603
```

## asin:

Goals: [], NaN, NaN, NaN ,NaN

```asind(hpf([]))
asind(hpf([2 -inf inf NaN]))
```
```ans =
[]
ans =
HPF element: (1,1)
NaN
HPF element: (1,2)
NaN
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
```

Goals: [0 1/6 -1/2]

```asin(hpf([0 0.5 -1],[200,3]))/hpf('pi',[200 3])
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
0.16666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667
HPF element: (1,3)
-0.5
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(2*rand(1,25) - 1,[50,2]);
log10(max(abs(asin(x) - asin(double(x)))))
```
```ans =
-15.026019950232380692416929376561154499744325891096
```

Sym comparison:

vpa(sin(sym('3')),100)

ans = 0.1411200080598672221007448028081102798469332642522655841518826412324220099670144719112821728534498638

```sin(hpf('3',100))
```
```ans =
0.1411200080598672221007448028081102798469332642522655841518826412324220099670144719112821728534498638
```

## asind:

Goals: [], NaN, NaN ,NaN

```asind(hpf([]))
asind(hpf([-inf inf NaN]))
```
```ans =
[]
ans =
HPF element: (1,1)
NaN
HPF element: (1,2)
NaN
HPF element: (1,3)
NaN
```

Goals: [0 30 -90]

```asind(hpf([0 0.5 -1],[200,3]))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
30
HPF element: (1,3)
-90
```

A set of random tests. The goal is a max log10 difference of roughly -13

```x = hpf(2*rand(1,25) - 1,[30 2]);
log10(max(abs(asind(x) - asind(double(x)))))
```
```ans =
-13.5781188848438398499957460068
```

## asinh:

empty begets empty

```asinh(hpf([]))
```
```ans =
[]
```

Goals: [-inf, 0, inf, NaN]

```asinh(hpf([-inf 0 inf NaN],50))
```
```ans =
HPF element: (1,1)
-Inf
HPF element: (1,2)
0
HPF element: (1,3)
Inf
HPF element: (1,4)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(20*rand(1,10) - 10);
log10(max(abs(double(asinh(x)) - asinh(double(x)))))
```
```ans =
-15.0514997831991
```

Sym comparison:

vpa(asinh(sym(17)),100)

ans = 3.527224456199965806371844321147769737181075325582383725627847771483069723308938434014739273560152791

```asinh(hpf('17',100))
```
```ans =
3.527224456199965806371844321147769737181075325582383725627847771483069723308938434014739273560152791
```

## atan:

empty begets empty

```atan(hpf([]))
```
```ans =
[]
```

Goals: [-1, 1, NaN]

```atan(hpf([-inf inf NaN],50))./(hpf('pi',50)./2)
```
```ans =
HPF element: (1,1)
-1
HPF element: (1,2)
1
HPF element: (1,3)
NaN
```

Goals: [0 -0.25]

```atan(hpf([0 -1],[200,3]))/hpf('pi',[200 3])
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
-0.25
```

Goal: 1

```atan(2 - sqrt(hpf(3,100)))*12/hpf('pi',100)
```
```ans =
1
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(20*rand(1,10) - 10);
log10(max(abs(double(atan(x)) - atan(double(x)))))
```
```ans =
-15.653559774527
```

Sym comparison:

vpa(atan(sym(17)),100)

ans = 1.512040504079173926329138389187979656621934281587108264343969733186463982719911941311562388925826973

```atan(hpf('17',100))
```
```ans =
1.512040504079173926329138389187979656621934281587108264343969733186463982719911941311562388925826973
```

## atand:

A set of random tests. The goal is a max log10 difference of roughly -13

```x = hpf(20*rand(1,25) - 10);
log10(max(abs(atand(x) - atand(double(x)))))
```
```ans =
-13.81096196069550755343748835306983867739986776237376723165288822
```

## atanh:

empty begets empty

```atanh(hpf([]))
```
```ans =
[]
```

Goals: [-inf, 0, inf, NaN]

```atanh(hpf([-1 0 1 NaN],50))
```
```ans =
HPF element: (1,1)
-Inf
HPF element: (1,2)
0
HPF element: (1,3)
Inf
HPF element: (1,4)
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(2*rand(1,10) - 1);
log10(max(abs(double(atanh(x)) - atanh(double(x)))))
```
```ans =
-15.653559774527
```

Sym comparison:

vpa(atanh(sym(0.5)),100)

ans = 0.5493061443340548456976226184612628523237452789113747258673471668187471466093044834368078774068660444

```atanh(hpf('0.5',100))
```
```ans =
0.5493061443340548456976226184612628523237452789113747258673471668187471466093044834368078774068660444
```

## cos: cosine function

empty begets empty

```cos(hpf([]))
```
```ans =
[]
```

Goals [1 -1 sqrt(2)/2 1/2 nan nan nan]

```X= [hpf(0), 3*hpf('pi',200), hpf('pi')/4, hpf('pi')/3, hpf(-inf) hpf(inf) hpf(nan)];
cos(X)
cos(double(X))
```
```ans =
HPF element: (1,1)
1
HPF element: (1,2)
-1
HPF element: (1,3)
0.7071067811865475244008443621048490392848359376884740365883398690
HPF element: (1,4)
0.5
HPF element: (1,5)
NaN
HPF element: (1,6)
NaN
HPF element: (1,7)
NaN
ans =
Columns 1 through 3
1                        -1         0.707106781186548
Columns 4 through 6
0.5                       NaN                       NaN
Column 7
NaN
```

A set of random tests. The goal is a max log10 difference of roughly -15

```x = hpf(2*pi*rand(1,25));
log10(max(abs(cos(x) - cos(double(x)))))
```
```ans =
-14.81828295011736687402409134881874567105303917637054278326181964
```

Sym comparison:

vpa(cos(sym('3')),100)

ans = -0.9899924966004454572715727947312613023936790966155883288140859329283291975131332204282944793556926022

```cos(hpf('3',100))
```
```ans =
-0.9899924966004454572715727947312613023936790966155883288140859329283291975131332204282944793556926022
```

## cosh:

empty begets empty

```sinh(hpf([]))
```
```ans =
[]
```

Goals: [1 inf inf NaN

```cosh(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
1
HPF element: (1,2)
Inf
HPF element: (1,3)
Inf
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.288164505228

```x = [-3 -2 -1 1 2 3];
log10(max(abs(double(cosh(hpf(x,[500 4])) - cosh(x)))))
```
```ans =
-15.288164505228
```

Sym comparison:

vpa(cosh(sym(1)),100)

ans = 1.543080634815243778477905620757061682601529112365863704737402214710769063049223698964264726435543036

```cosh(hpf(1,100))
```
```ans =
1.543080634815243778477905620757061682601529112365863704737402214710769063049223698964264726435543036
```

## coth:

empty begets empty

```sinh(hpf([]))
```
```ans =
[]
```

Goals: [Inf -1 1 NaN

```coth(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
Inf
HPF element: (1,2)
-1
HPF element: (1,3)
1
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.8016545031234

```x = [-3 -2 -1 1 2 3];
log10(max(abs(double(coth(hpf(x,[500 4])) - coth(x)))))
```
```ans =
-15.8016545031234
```

Sym comparison:

vpa(coth(sym(1)),100)

ans = 1.313035285499331303636161246930847832912013941240452655543152967567084270461874382674679241480856303

```coth(hpf(1,100))
```
```ans =
1.313035285499331303636161246930847832912013941240452655543152967567084270461874382674679241480856303
```

## cubrt

Goals: [0, 0, -1.1, 8.37, inf, -inf, NaN]

```cubrt(exp(hpf('3',500))) - hpf('e',500)
cubrt(hpf('-1.331',1000))
cubrt(hpf('586.376253',250))
cubrt(hpf([inf -inf NaN]))
```
```ans =
-6.e-503
ans =
-1.1
ans =
8.37
ans =
HPF element: (1,1)
Inf
HPF element: (1,2)
-Inf
HPF element: (1,3)
NaN
```

## DefaultDecimalBase: sets the default working base for HPF

Goal

```sqrt(pi*exp(1) + 2) - 4/3
```
```ans =
1.91316235011884
```

Decimal bases of 1:6, should all yield the same result

```DefaultNumberOfDigits 50 1
DefaultDecimalBase 1
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3

DefaultDecimalBase 2
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3

DefaultDecimalBase 3
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3

DefaultDecimalBase 4
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3

DefaultDecimalBase 5
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3

DefaultDecimalBase 6
sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3
```
```ans =
1.9131623501188358458269603326053071190889845559662
ans =
1.9131623501188358458269603326053071190889845559662
ans =
1.9131623501188358458269603326053071190889845559662
ans =
1.9131623501188358458269603326053071190889845559662
ans =
1.9131623501188358458269603326053071190889845559662
ans =
1.9131623501188358458269603326053071190889845559662
```

A time test, with 35000 digits. Time for a multiply in HPF should be roughly inversely quadratic, but adds and subtracts are not so strongly a function of the decimal base, although at worst linear in the number of digits, and divides (and other ops like sqrt) will be a mixture of adds and multiplies.

Time tests for a pure add

```DefaultNumberOfDigits 35000 0
DefaultDecimalBase 1
timeit(@() hpf('pi') + hpf('e'))

DefaultDecimalBase 2
timeit(@() hpf('pi') + hpf('e'))

DefaultDecimalBase 3
timeit(@() hpf('pi') + hpf('e'))

DefaultDecimalBase 4
timeit(@() hpf('pi') + hpf('e'))

DefaultDecimalBase 5
timeit(@() hpf('pi') + hpf('e'))

DefaultDecimalBase 6
timeit(@() hpf('pi') + hpf('e'))
```
```ans =
0.004223169908
ans =
0.003327785908
ans =
0.002851153908
ans =
0.002651351908
ans =
0.002329971908
ans =
0.002327376908
```

Time tests for a pure multiply

```DefaultDecimalBase 1
timeit(@() hpf('pi').*hpf('e'))

DefaultDecimalBase 2
timeit(@() hpf('pi').*hpf('e'))

DefaultDecimalBase 3
timeit(@() hpf('pi').*hpf('e'))

DefaultDecimalBase 4
timeit(@() hpf('pi').*hpf('e'))

DefaultDecimalBase 5
timeit(@() hpf('pi').*hpf('e'))

DefaultDecimalBase 6
timeit(@() hpf('pi').*hpf('e'))
```
```ans =
0.166514478908
ans =
0.050843273908
ans =
0.029779401908
ans =
0.017803268908
ans =
0.013657327908
ans =
0.011297569908
```

Time tests for a pure divide

```DefaultDecimalBase 1
tic, hpf('pi')./hpf('e');toc

DefaultDecimalBase 2
tic, hpf('pi')./hpf('e');toc

DefaultDecimalBase 3
tic, hpf('pi')./hpf('e');toc

DefaultDecimalBase 4
tic, hpf('pi')./hpf('e');toc

DefaultDecimalBase 5
tic, hpf('pi')./hpf('e');toc

DefaultDecimalBase 6
tic, hpf('pi')./hpf('e');toc
```
```Elapsed time is 4.505691 seconds.
Elapsed time is 1.196788 seconds.
Elapsed time is 0.689662 seconds.
Elapsed time is 0.419039 seconds.
Elapsed time is 0.337060 seconds.
Elapsed time is 0.402174 seconds.
```

Time tests for a mixed operation

```DefaultDecimalBase 1
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc

DefaultDecimalBase 2
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc

DefaultDecimalBase 3
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc

DefaultDecimalBase 4
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc

DefaultDecimalBase 5
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc

DefaultDecimalBase 6
tic,sqrt(hpf('pi')*hpf('e') + 2) - hpf(4)/3;toc
```
```Elapsed time is 5.956570 seconds.
Elapsed time is 1.981532 seconds.
Elapsed time is 1.086320 seconds.
Elapsed time is 0.707436 seconds.
Elapsed time is 0.540060 seconds.
Elapsed time is 0.449797 seconds.
```

## eq:

```DefaultNumberOfDigits 64 4
X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X == Y
```
```ans =
0     1     0     0     0     0     0     0     1
```

Expected result

```double(X) == double(Y)
```
```ans =
0     1     0     0     0     0     0     0     1
```

## erf

empty begets empty

```erf(hpf([]))
```
```ans =
[]
```

Goals: [-1 0 1 NaN]

```erf(hpf([-inf 0 inf NaN]))
```
```ans =
HPF element: (1,1)
-1
HPF element: (1,2)
0
HPF element: (1,3)
1
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -16.2705600471626

```x = -5:2:5;
log10(max(abs(double(erf(hpf(x,[20 4])) - erf(x)))))
```
```ans =
-16.2705600471626
```

Sym comparison:

vpa(erf(sym(9)),100)

ans = 0.9999999999999999999999999999999999995862968253486189761946096532637475404289808014052037540194090098

```erf(hpf('9',100))
```
```ans =
0.9999999999999999999999999999999999995862968253486189761946096532637475404289808014052037540194090098
```

## exp:

empty begets empty

```exp(hpf([]))
```
```ans =
[]
```

Goals: [0,1,exp(1),inf,nan,10]

```X = [hpf([-inf 0 1 inf nan]),hpf('ln10')];
exp(X)
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
1
HPF element: (1,3)
2.718281828459045235360287471352662497757247093699959574966967628
HPF element: (1,4)
Inf
HPF element: (1,5)
NaN
HPF element: (1,6)
10
```

Fixed tests: Goal is -14.4576292646912

```x = -5:2:5;
log10(max(abs(double(exp(hpf(x,[20 4])) - exp(x)))))
```
```ans =
-14.4576292646912
```

Sym comparison:

vpa(exp(sym('5/2')),100)

ans = 12.18249396070347343807017595116796618318276779006316131156039834183818512614331441006025552300629579

```exp(hpf('2.5',100))
```
```ans =
12.18249396070347343807017595116796618318276779006316131156039834183818512614331441006025552300629579
```

## factorial:

factorial(sym(75))

ans = 24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000

```factorial(hpf(75,200))
```
```ans =
24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000
```

## fix:

empty begets empty

```fix(hpf([]))
```
```ans =
[]
```

Goals: [-inf inf NaN]

```fix(hpf([-inf inf NaN],23))
```
```ans =
HPF element: (1,1)
-Inf
HPF element: (1,2)
Inf
HPF element: (1,3)
NaN
```

Goal

```Xd = (-10:10)*pi/10;
fix(Xd)
```
```ans =
Columns 1 through 13
-3    -2    -2    -2    -1    -1    -1     0     0     0     0     0     0
Columns 14 through 21
0     1     1     1     2     2     2     3
```
```fix(hpf(Xd,[20,0]))
```
```ans =
HPF element: (1,1)
-3
HPF element: (1,2)
-2
HPF element: (1,3)
-2
HPF element: (1,4)
-2
HPF element: (1,5)
-1
HPF element: (1,6)
-1
HPF element: (1,7)
-1
HPF element: (1,8)
0
HPF element: (1,9)
0
HPF element: (1,10)
0
HPF element: (1,11)
0
HPF element: (1,12)
0
HPF element: (1,13)
0
HPF element: (1,14)
0
HPF element: (1,15)
1
HPF element: (1,16)
1
HPF element: (1,17)
1
HPF element: (1,18)
2
HPF element: (1,19)
2
HPF element: (1,20)
2
HPF element: (1,21)
3
```

Should be entirely true:

```double(fix(hpf(Xd,[20,0]))) == fix(Xd)
```
```ans =
Columns 1 through 13
1     1     1     1     1     1     1     1     1     1     1     1     1
Columns 14 through 21
1     1     1     1     1     1     1     1
```

## floor: round towards -inf

Empty begets empty

```floor(hpf([]))
```
```ans =
[]
```

Expected results: [3,-314160 12345678901 -1234567890123456789 0 -inf NaN]

```X = [hpf('pi'), -1e5*hpf('pi'), hpf('12345678901'), ...
hpf('-123456789012345678901'), hpf([0, -inf, nan])]
floor(X)
```
```X =
HPF element: (1,1)
3.141592653589793238462643383279502884197169399375105820974944592
HPF element: (1,2)
-314159.2653589793238462643383279502884197169399375105820974944592
HPF element: (1,3)
12345678901
HPF element: (1,4)
-123456789012345678901
HPF element: (1,5)
0
HPF element: (1,6)
-Inf
HPF element: (1,7)
NaN
ans =
HPF element: (1,1)
3
HPF element: (1,2)
-314160
HPF element: (1,3)
12345678901
HPF element: (1,4)
-123456789012345678902
HPF element: (1,5)
0
HPF element: (1,6)
-Inf
HPF element: (1,7)
NaN
```

## fractionalpart:

Empty begets empty

```fractionalpart(hpf([]))
```
```ans =
[]
```

Goals: [0.141590, -0.345 0 0 NaN NaN NaN]

```DefaultDecimalBase 6
fractionalpart(hpf('pi',[6 0]))
fractionalpart(hpf('-12.345'))
fractionalpart(hpf([0 10000 -inf inf NaN]))
```
```ans =
0.141590
ans =
-0.345
ans =
HPF element: (1,1)
0
HPF element: (1,2)
0
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
HPF element: (1,5)
NaN
```

## ge:

```X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X >= Y
```
```ans =
0     1     0     0     1     0     1     0     1
```

Expected result

```double(X) >= double(Y);
```

Random tests, Goal: 1

```x = hpf(1 + (rand(1,10) - 0.5)/100000);
y = hpf(1 + (rand(1,10) - 0.5)/100000);
all((x >= y) == (double(x) >= double(y)))
```
```ans =
1
```

## gt:

```X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X > Y
```
```ans =
0     0     0     0     1     0     1     0     0
```

Expected result

```double(X) > double(Y)
```
```ans =
0     0     0     0     1     0     1     0     0
```

Random tests, Goal: 1

```x = hpf(1 + (rand(1,10) - 0.5)/100000);
y = hpf(1 + (rand(1,10) - 0.5)/100000);
all((x > y) == (double(x) > double(y)))
```
```ans =
1
```

## hpf:

empty begets empty

```hpf([])
```
```ans =
[]
```

Goal: 0

```hpf
```
```ans =
0
```

Goals: [0 1 -inf inf NaN]

```hpf([0 1 -inf inf NaN])
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
1
HPF element: (1,3)
-Inf
HPF element: (1,4)
Inf
HPF element: (1,5)
NaN
```

Goals: [1.23, 1.229999999999999982236431605997495353221893310546875000]

```hpf('1.23')
hpf(1.23)
```
```ans =
1.23
ans =
1.229999999999999982236431605997495353221893310546875000000000000
```

Goals: [123456.7, 12345.67, 12.34567, 1.234567e10000, -12.1212121]

```hpf('1.234567e5')
hpf('0.1234567e5')
hpf('1234.567e-2')
hpf('1234567e10000')
hpf('-12.1212121e0')
```
```ans =
123456.7
ans =
12345.67
ans =
12.34567
ans =
1.234567e10000
ans =
-12.1212121
```

Goal: 1.2345678901234567890123e29

```hpf('123456789012345678901234567890',23)
```
```ans =
1.2345678901234567890123e29
```

## isfinite:

empty begets empty

```isfinite(hpf([]))
```
```ans =
[]
```

goals: [1 1 1 0 0 0]

```isfinite(hpf([0 pi -4 NaN inf -inf]))
```
```ans =
1     1     1     0     0     0
```

## isinf:

empty begets empty

```isinf(hpf([]))
```
```ans =
[]
```

goals: [0 0 0 0 1 1]

```isinf(hpf([0 pi -4 NaN inf -inf]))
```
```ans =
0     0     0     0     1     1
```

## isnan:

empty begets empty

```isnan(hpf([]))
```
```ans =
[]
```

goals: [0 0 0 1 0 0]

```isnan(hpf([0 pi -4 NaN inf -inf]))
```
```ans =
0     0     0     1     0     0
```

## isnumeric:

Goal: 1 (true)

```isnumeric(hpf)
```
```ans =
1
```

## le: <=, less than or equal to

```X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X <= Y
```
```ans =
1     1     0     0     0     1     0     1     1
```

Expected result

```double(X) <= double(Y)
```
```ans =
1     1     0     0     0     1     0     1     1
```

## log10:

Goals: [], -inf, inf, NaN

```log10(hpf([]))
log10(hpf(0))
log10(hpf(inf))
log10(hpf(NaN))
```
```ans =
[]
ans =
-Inf
ans =
Inf
ans =
NaN
```

Goals: [50, 100000000000000000000000000000000000000000000000001]

```DefaultNumberOfDigits 200 5
X = hpf('100000000000000000000000000000000000000000000000000');
log10(X)
10.^(log10(X+1))
```
```ans =
50
ans =
100000000000000000000000000000000000000000000000001
```

Sym comparison:

vpa(log10(sym('17')),100)

ans = 1.23044892137827392854016989432833703000756737842504639738036848234469406225711818579568467009846514

```log10(hpf('17',100))
```
```ans =
1.230448921378273928540169894328337030007567378425046397380368482344694062257118185795684670098465140
```

## log2:

Goals: [], -inf, inf, NaN

```log2(hpf([]))
log2(hpf(0))
log2(hpf(inf))
log2(hpf(NaN))
```
```ans =
[]
ans =
1
ans =
Inf
ans =
NaN
```

Goals: [19520]

```X = hpf('1048576',[50 5]).^976;
log2(X)
```
```ans =
19520
```

Sym comparison:

vpa(log2(sym('17')),100)

ans = 4.087462841250339408254066010810404354011267282344820688126609064386696509047382068297343151843684273

```log2(hpf('17',100))
```
```ans =
4.087462841250339408254066010810404354011267282344820688126609064386696509047382068297343151843684273
```

## lt: <, less than

```X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X < Y
```
```ans =
1     0     0     0     0     1     0     1     0
```

Expected result

```double(X) < double(Y)
```
```ans =
1     0     0     0     0     1     0     1     0
```

## ne:

```X = hpf([-inf inf NaN 3   2.5 -1.37 5 6.2999999999999 6.4]);
Y = hpf([inf inf  inf NaN -1   0    2 6.3999999999999 6.4]);
X ~= Y
```
```ans =
1     0     1     1     1     1     1     1     0
```

Expected result

```double(X) ~= double(Y)
```
```ans =
1     0     1     1     1     1     1     1     0
```

## plus:

empty begets empty, as an empty HPF result

```[] + hpf(pi)
```
```ans =
[]
```

Goals: [NaN, inf, NaN, NaN, 1.5 0],

```X = hpf([-inf inf NaN 3   2.5 pi]);
Y = hpf([inf inf  inf NaN -1  -pi]);
X + Y
```
```ans =
HPF element: (1,1)
NaN
HPF element: (1,2)
Inf
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
HPF element: (1,5)
1.5
HPF element: (1,6)
0
```

Goal: 1.234567, with NumberOfDigts == [6 0]

```hpf('1.11111111111111111111',[20 0]) + hpf('0.123456',[6 0])
ans.NumberOfDigits
```
```ans =
1.23457
ans =
6     0
```

## reciprocal: Computes the scalar inverse of a number, 1./F

empty begets empty

```reciprocal(hpf([]))
```
```ans =
[]
```

Goals: [inf, NaN, 0, 0]

```reciprocal(hpf([0, NaN, -inf, inf]))
```
```ans =
HPF element: (1,1)
Inf
HPF element: (1,2)
NaN
HPF element: (1,3)
0
HPF element: (1,4)
0
```

a set of tests on reciprocals of some integers. Goal is -16.255619765855

```log10(max(abs(double(reciprocal(hpf(1:50,20))) - 1./(1:50))))
```
```ans =
-16.255619765855
```

A set of reciprocals of some random numbers. Goal is roughly -14

```x = sort(rand(1,20) - 1);
log10(max(abs(double(reciprocal(hpf(x,[30 2]))) - 1./x)))
```
```ans =
-14.5743785284794
```

## sec

empty begets empty

```sec(hpf([]))
```
```ans =
[]
```

Goals: [inf inf 1 NaN NaN NaN]

```sec(-hpf('pi',40)/2)
sec(hpf('pi',40)/2)
sec(hpf([0 -inf inf NaN]))
```
```ans =
1.e47
ans =
Inf
ans =
HPF element: (1,1)
1
HPF element: (1,2)
NaN
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.083071513751

```x = 1:10;
log10(max(abs(double(sec(hpf(x,[20 4])) - sec(x)))))
```
```ans =
-15.083071513751
```

Sym comparison:

vpa(sec(sym(17)),100)

ans = -3.634205076449851045700145553853416971812501547277707974413306626204205786111854275175875759446174066

```sec(hpf('17',100))
```
```ans =
-3.634205076449851045700145553853416971812501547277707974413306626204205786111854275175875759446174066
```

## sech:

empty begets empty

```sech(hpf([]))
```
```ans =
[]
```

Goals: [0 1 0 NaN]

```sech(hpf([-inf 0 inf NaN]))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
1
HPF element: (1,3)
0
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.083071513751

```x = 1:10;
log10(max(abs(double(sec(hpf(x,[20 4])) - sec(x)))))
```
```ans =
-15.083071513751
```

Sym comparison:

vpa(sech(sym(17)),100)

ans = 0.00000008279875437570319128353730868526605265319669601947623809070883019333038402979377756328623635837203043

```sech(hpf('17',100))
```
```ans =
0.00000008279875437570319128353730868526605265319669601947623809070883019333038402979377756328623635837203043
```

## sin:

empty begets empty

```sin(hpf([]))
```
```ans =
[]
```

Goals: [0 NaN NaN NaN]

```sin(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
NaN
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -16.3104935951442

```x = 1:10;
log10(max(abs(double(sin(hpf(x,[20 4])) - sin(x)))))
```
```ans =
-16.3104935951442
```

special values, goals: 0 (to within 250 digits)

```x = hpf('pi',250)./[6 4 3 2 1]
sin(x) - [0.5 sqrt(hpf(2,250))/2 sqrt(hpf(3,250))/2 1 0]
```
```x =
HPF element: (1,1)
0.5235987755982988730771072305465838140328615665625176368291574320513027343810348331046724708903528446636913477522137177745156407682584303719542265680214135195750473504503230868509266074371581591550636607381351626109889076880792747056311305275452003182
HPF element: (1,2)
0.7853981633974483096156608458198757210492923498437764552437361480769541015715522496570087063355292669955370216283205766617734611523876455579313398520321202793625710256754846302763899111557372387325954911072027439164833615321189120584466957913178004773
HPF element: (1,3)
1.047197551196597746154214461093167628065723133125035273658314864102605468762069666209344941780705689327382695504427435549031281536516860743908453136042827039150094700900646173701853214874316318310127321476270325221977815376158549411262261055090400636
HPF element: (1,4)
1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412671058533991074043256641153323546922304775291115862679704064240558725142051350969260552779822311474477465190982214405487832966723064237824116893391582635600955
HPF element: (1,5)
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909
ans =
HPF element: (1,1)
0
HPF element: (1,2)
-3.e-258
HPF element: (1,3)
0
HPF element: (1,4)
0
HPF element: (1,5)
0
```

Sym comparison:

vpa(sin(sym(17)),100)

ans = -0.961397491879556857261636944869156098492067254058935985601562874569876633233567787053089546435476294

```sin(hpf('17',100))
```
```ans =
-0.9613974918795568572616369448691560984920672540589359856015628745698766332335677870530895464354762940
```

## sinh:

empty begets empty

```sinh(hpf([]))
```
```ans =
[]
```

Goals: [0 -inf inf NaN

```sinh(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
-Inf
HPF element: (1,3)
Inf
HPF element: (1,4)
NaN
```

Random tests: Goal is -15.1562753989016

```x = [-3 -2 -1 1 2 3];
log10(max(abs(double(sinh(hpf(x,[500 4])) - sinh(x)))))
```
```ans =
-15.1562753989016
```

Test of a large value. Goal: -2.57653587596...e-869

```x = sinh(hpf(1000,[1000 5]));
log(x) + log(hpf('2',[1000 5])) - 1000
```
```ans =
-2.576535872961149652190150499507352912722130573760632202117945887577138639143490471433788940258775081822660822244694084549856860357608167e-869
```

Sym comparison:

vpa(sinh(sym(1)),100)

ans = 1.175201193643801456882381850595600815155717981334095870229565413013307567304323895607117452089623392

```sinh(hpf(1,100))
```
```ans =
1.175201193643801456882381850595600815155717981334095870229565413013307567304323895607117452089623392
```

## sqrt:

empty begets empty

```sqrt(hpf([]))
```
```ans =
[]
```

Goals: [0 NaN inf NaN]

A warning will be issued for sqrt(-1)

```sqrt(hpf([0 -1 inf NaN]))
```
```Warning: sqrt of negative value. Only real HPF numbers are currently supported
ans =
HPF element: (1,1)
0
HPF element: (1,2)
NaN
HPF element: (1,3)
Inf
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.6638172422041

```x = 2:10;
log10(max(abs(double(sqrt(hpf(x,[20 4])) - sqrt(x)))))
```
```ans =
-15.6638172221778
```

Sym comparison:

vpa(sqrt(sym(23)),100)

ans = 4.795831523312719541597438064162693919996707041904129346485309114448257235907464082492191446436918861

```sqrt(hpf('23',100))
```
```ans =
4.795831523312719541597438064162693919996707041904129346485309114448257235907464082492191446436918861
```

## tan:

empty begets empty

```tan(hpf([]))
```
```ans =
[]
```

Goals: [0 NaN NaN NaN]

```tan(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
1
HPF element: (1,2)
NaN
HPF element: (1,3)
NaN
HPF element: (1,4)
NaN
```

Goals: [-inf inf]

```tan(hpf('pi',100)*[-.5 .5])
```
```ans =
HPF element: (1,1)
-Inf
HPF element: (1,2)
Inf
```

Fixed tests: Goal is -15.5108867853615

```x = 1:10;
log10(max(abs(double(tan(hpf(x,[20 4])) - tan(x)))))
```
```ans =
-15.5108867853615
```

special values, goals: 0 (to within 1e-150

```x = hpf('pi',150)./[6 4 3]
tan(x) - [sqrt(hpf(3,150))/3 1 sqrt(hpf(3,250))]
```
```x =
HPF element: (1,1)
0.523598775598298873077107230546583814032861566562517636829157432051302734381034833104672470890352844663691347752213717774515640768258430371954226568021
HPF element: (1,2)
0.785398163397448309615660845819875721049292349843776455243736148076954101571552249657008706335529266995537021628320576661773461152387645557931339852032
HPF element: (1,3)
1.04719755119659774615421446109316762806572313312503527365831486410260546876206966620934494178070568932738269550442743554903128153651686074390845313604
ans =
HPF element: (1,1)
-1.3e-155
HPF element: (1,2)
0
HPF element: (1,3)
-2.e-155
```

Sym comparison:

vpa(tan(sym(17)),100)

ans = 3.493915645474839978346364290913980748486600343707345139970378981729932323805208911327226624805744553

```tan(hpf('17',100))
```
```ans =
3.493915645474839978346364290913980748486600343707345139970378981729932323805208911327226624805744553
```

## tanh:

empty begets empty

```tanh(hpf([]))
```
```ans =
[]
```

Goals: [0 -1 1 NaN]

```tanh(hpf([0 -inf inf NaN]))
```
```ans =
HPF element: (1,1)
0
HPF element: (1,2)
-1
HPF element: (1,3)
1
HPF element: (1,4)
NaN
```

Fixed tests: Goal is -15.8487333751523

```x = 0.1:.1:1;
log10(max(abs(double(tanh(hpf(x,[20 4])) - tanh(x)))))
```
```ans =
-15.8487333751523
```

Sym comparison:

vpa(tanh(sym(17)),100)

ans = 0.9999999999999965721831369159799423587827364437255846875211707191426378969848776206130640331425577278

```tanh(hpf('17',100))
```
```ans =
0.9999999999999965721831369159799423587827364437255846875211707191426378969848776206130640331425577278
```

## vpi:

Restore the System state to whatever it was before this test was run.

```DefaultDecimalBase(OriginalDecimalBase)
DefaultNumberOfDigits(OriginalNDig)
```