GNU Multiple precision library
libgmp
gmp-6.2.0\win64\static\libgmp.a を FreeBASIC-1.07.1-win64\lib\win64 ディレクトリーにコピーする
使用例
5432
ソースコード
#Include once "gmp.bi"
Dim Shared As Zstring * 100000000 outtext
Function Power(number As String,n As Uinteger) As String'automate precision
#define dp 3321921
Dim As __mpf_struct _number,FloatAnswer
Dim As Ulongint ln=Len(number)*(n)*4
If ln>dp Then ln=dp
mpf_init2(@FloatAnswer,ln)
mpf_init2(@_number,ln)
mpf_set_str(@_number,number,10)
mpf_pow_ui(@Floatanswer,@_number,n)
gmp_sprintf( @outtext,"%." & Str(n) & "Ff",@FloatAnswer )
Var outtxt=Trim(outtext)
If Instr(outtxt,".") Then outtxt= Rtrim(outtxt,"0"):outtxt=Rtrim(outtxt,".")
Return Trim(outtxt)
End Function
Print "GMP version ";*gmp_version
Print
var ans=power("5",(4^(3^2)))
Print Left(ans,20) + " ... "+Right(ans,20)
Print "Number of digits ";Len(ans)
Sleep
コードは、rosettacode から一部修正し引用した。
コンパイル
fbc -v gmpPower.bas
FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win64 (64bit)
Copyright (C) 2004-2019 The FreeBASIC development team.
standalone
target: win64, x86-64, 64bit
compiling: gmpPower.bas -o gmpPower.c (main module)
compiling C: D:\sumio\FreeBASIC-1.07.1-win64\bin\win64\gcc.exe -m64 -march=x86-64 -S -nostdlib -nostdinc -Wall -Wno-unused-label -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format -masm=intel "gmpPower.c" -o "gmpPower.asm"
assembling: D:\sumio\FreeBASIC-1.07.1-win64\bin\win64\as.exe --64 --strip-local-absolute "gmpPower.asm" -o "gmpPower.o"
linking: D:\sumio\FreeBASIC-1.07.1-win64\bin\win64\ld.exe -m i386pep -o "gmpPower.exe" -subsystem console "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64\fbextra.x" --stack 1048576,1048576 -s -L "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64" -L "." "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64\crt2.o" "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64\crtbegin.o" "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64\fbrt0.o" "gmpPower.o" "-(" -lgmp -lfb -lgcc -lmsvcrt -lkernel32 -luser32 -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "D:\sumio\FreeBASIC-1.07.1-win64\lib\win64\crtend.o"
実行結果
gmpPower
GMP version 6.2.0
62060698786608744707 ... 92256259918212890625
Number of digits 183231