Object
|
+---DBigDouble
The big double class implements a number of methods for working with arbitrary large double numbers. The class uses the excellent gmp library for the actual calculations. Note: setting the precision (as is done by move: and point:) will result in a realloc)
#include <stdio.h>
#include "ofc/DBigDouble.h"
#include "ofc/DText.h"
int main(int argc, char *argv[])
{
DBigDouble *dbl1 = [DBigDouble alloc];
DBigDouble *dbl2 = [DBigDouble new ];
DBigDouble *dbl3 = [DBigDouble new ];
DText *str;
[dbl1 init :3.14143123423234322343223432 :256]; // Init with pi, with 256 precision bits
[dbl2 move :dbl1]; // Move dbl1 in dbl2
[dbl2 mul :dbl1]; // Multiply dbl2 with dbl1 -> PI^2
[dbl3 sub :dbl2 :dbl1]; // dbl3 = dbl2 - dbl1 = PI^2 - PI
printf("PI^2 - PI=%f\n", [dbl3 get]); // Get dbl3 as double number
str = [dbl3 get :10 :15]; // Convert to string, base 10, 15 digits
printf("PI^2 - PI=%s\n", [str cstring]);
if ([dbl1 compare :dbl2] == 0) // Compare numbers
printf("Double1 is equal to double2\n");
else if ([dbl1 compare :dbl2] < 0)
printf("Double1 is smaller than double2\n");
else
printf("Double1 is greater than double2\n");
[str free]; // Cleanup
[dbl3 free];
[dbl2 free];
[dbl1 free];
return 0;
}