Arbitrary-precision integers (included): Difference between revisions

Content deleted Content added
Langurmonkey (talk | contribs)
Richlove (talk | contribs)
Line 1,022:
println["Length=" + length[as] + ", " + left[as,20] + "..." + right[as,20]]</syntaxhighlight>
This prints <CODE>Length=183231, 62060698786608744707...92256259918212890625</CODE>
 
=={{header|FutureBasic}}==
Translated from c
 
Thanks Ken
<syntaxhighlight lang="futurebasic">
/*
Requires FutureBasic 7.0.27 or later
 
Uses GMP for Multiple Precision Arithmetic
Install GMP using terminal and Homebrew command, "brew install gmp"
before running this app in FutureBasic.
 
Homebrew available here, https://brew.sh
 
*/
 
void local fn GMPoutput
CFURLRef desktopURL = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
CFURLRef url = fn URLByAppendingPathComponent( desktopURL, @"gmp-output.m" )
CFStringRef gmpStr = ¬
@"#import <Foundation/Foundation.h>\n¬
#import <gmp.h>\n¬
int main(int argc, const char * argv[]) {\n¬
@autoreleasepool {\n¬
mpz_t a;\n¬
mpz_init_set_ui(a, 5);\n¬
mpz_pow_ui(a, a, 1 << 18);\n¬
size_t len = mpz_sizeinbase(a, 10);\n¬
printf(\" GMP says the size is: %zu\\n\", len);\n¬
char *s = mpz_get_str(0, 10, a);\n¬
size_t trueLen = strlen(s);\n¬
printf(\"Confirmed. The size is %zu\\n\", trueLen);\n¬
printf(\"Digits: %.20s…%s\\n\", s, s + trueLen - 20);\n¬
}\n¬
return 0;\n¬
}"
fn StringWriteToURL( gmpStr, url, YES, NSUTF8StringEncoding, NULL ) // Create gmp-output.m on desktop
end fn
 
fn GMPoutput
 
unix @"clang -o ~/Desktop/GMP_output ~/Desktop/gmp-output.m -lgmp -fobjc-arc" // Create GMP_output on desktop
unix @"~/Desktop/GMP_output > ~/Desktop/gmp-output.txt" // Create gmp-output.txt on desktop
unix @"open ~/Desktop/gmp-output.txt" // Open gmp-output.txt to show results
unix @"rm ~/Desktop/GMP_output" : unix @"rm ~/Desktop/gmp-output.m" // Remove GMP_output and gmp-output.m from desktop
 
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
GMP says the size is: 183231
Confirmed. The size is 183231
Digits: 62060698786608744707…92256259918212890625
</pre>
 
=={{header|Fōrmulæ}}==