请教一个 Dll 的结构类型转换 VFP 的问题

回马枪 2014-10-10 03:28:17

' 首先定义三个结构类:MPZ、MPQ、MPF
Type MPZ ' multiprecision integer
mp_alloc As Long
mp_size As Long
mp_limb As Long
End Type

Type MPQ ' multiprecision rational
mp_num As MPZ
mp_den As MPZ
End Type

Type MPF ' multiprecision floating point
mp_prec As Long
mp_size As Long
mp_expt As Long
mp_limb As Long
End Type

'=== Integer 类型===
'initialize (reserve memory) for multiprecision integer
Declare Sub MPZinit CDecl Lib "gmp.dll" Alias "__gmpz_init" (X As MPZ)
'x = val(s$) number base b
Declare Sub MPZsetstr CDecl Lib "gmp.dll" Alias "__gmpz_set_str" (X As MPZ, s As Asciiz, ByVal b As Long)
'y = x
Declare Sub MPZset CDecl Lib "gmp.dll" Alias "__gmpz_set" (Y As MPZ, X As MPZ)
'y = x + z

如果转成 VFP 函数;
DECLARE MPZinit IN gmp.dll As __gmpz_init MPZ @X
DECLARE MPZsetstr IN gmp.dll As __gmpz_set_str MPZ @X, Asciiz @s, Integer b
DECLARE MPZset IN gmp.dll As __gmpz_set MPZ @Y, MPZ @X

那么 :MPZ、MPQ、MPF 的结构如何转换或定义?

谢谢
...全文
429 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
sych11 2014-10-11
  • 打赏
  • 举报
回复
同意楼上,正解
回马枪 2014-10-11
  • 打赏
  • 举报
回复
以前我是在这个网站下载的 GM-GMP.Dll:http://gmc.yoyogames.com/index.php?showtopic=484933 这个是简洁版 只有20个左右的函数 VFP 调用没有像全版的这么复杂 代码见下面 全版的有500-600个函数 我想使用全版的 libgmp-510.dll

Clear


? "求实部函数:"  && 
*!*    This function does exactly the same as real(), but it supports hexadecimal, octal and binary as well, so it can be used to convert the result of mathematical functions to reals. It doesn't support an exponential part though.
*!*    function gmp_real(a_string:string):real
Declare Double gmp_real In gm-gmp.Dll String a_string
Ret = gmp_real("1.234e-24")  && > 0
?? Ret


? "10b 转 16b:"
*!*    function gmp_string(a_real:real):string
Declare String gmp_string In gm-gmp.Dll Double a_real
Ret = gmp_string(11)  && 0xb
?? Ret


? "Str 转 16b:"
*!*    function gmp_tohex(a_string:string):string
Declare String gmp_tohex In gm-gmp.Dll String a_string
Ret = gmp_tohex("11")  && 0xb
?? Ret


? "16b 转 10b:"
*!*    function gmp_todec(a_string:string):string
Declare String gmp_todec In gm-gmp.Dll String a_string
?? gmp_todec("0xb")  && 11


? "算数函数======================================"
? "加法函数  :"
*!*    function gmp_add(a_string:string;b_string:string):string
Declare String gmp_add In gm-gmp.Dll String a_string, String b_string
Ret = gmp_add(Replicate("1", 20), Replicate("2", 20))
?? gmp_todec(Ret)  && 20个3


? "减法函数  :"
*!*    function gmp_sub(a_string:string;b_string:string):string
Declare String gmp_sub In gm-gmp.Dll String a_string, String b_string
Ret = gmp_sub(Replicate("3", 20), Replicate("1", 20))
?? gmp_todec(Ret)  && 20个2


? "乘法函数  :"
*!*    function gmp_mul(a_string:string;b_string:string):string
Declare String gmp_mul In gm-gmp.Dll String a_string, String b_string
Ret = gmp_mul(Replicate("3", 5), Replicate("3", 5))
?? gmp_todec(Ret)  && 33333 * 33333 = 1111088889


? "除法函数  :"  && 零舍入
*!*    function gmp_div(a_string:string;b_string:string):string
Declare String gmp_div In gm-gmp.Dll String a_string, String b_string
Ret = gmp_div(Replicate("3", 20), Replicate("1", 20))
?? gmp_todec(Ret)  && 3


? "取模函数  :"
*!*    function gmp_mod(a_string:string;b_string:string):string
Declare String gmp_mod In gm-gmp.Dll String a_string, String b_string
Ret = gmp_mod("5", "3")
?? gmp_todec(Ret)  && 2


? "取反函数  :"
*!*    function gmp_neg(a_string:string):string
Declare String gmp_neg In gm-gmp.Dll String a_string
Ret = gmp_neg("5")
?? gmp_todec(Ret)  && -5


? "绝对值函数:"
*!*    function gmp_abs(a_string:string):string
Declare String gmp_abs In gm-gmp.Dll String a_string
Ret = gmp_abs("-5")
?? gmp_todec(Ret)  && 5


? "指数函数======================================"
? "幂函数    :"
*!*    function gmp_pow(a_string:string;n_string:string):string
Declare String gmp_pow In gm-gmp.Dll String a_string, String n_string
Ret = gmp_pow("5", "2")
?? gmp_todec(Ret)  && 5^2 = 25


? "带余数幂  :"  && 类似于:gmp_pow(gmp_sqrt(a), 2)
*!*    function gmp_powmod(a_string:string;n_string:string;mod_string:string):string
Declare String gmp_powmod In gm-gmp.Dll String a_string, String n_string, String mod_string
Ret = gmp_powmod("5", "2", "3")
?? gmp_todec(Ret)  && Mod(5^2, 3) = 1


? "求根开方函数=================================="
? "平方根函数:"  && 结果舍入到零
*!*    function gmp_sqrt(a_string:string):string
Declare String gmp_sqrt In gm-gmp.Dll String a_string
Ret = gmp_sqrt("7")
?? gmp_todec(Ret)  && sqrt("7") = 2


? "平方根余数:"
*!*    function gmp_sqrtrem(a_string:string):string
Declare String gmp_sqrtrem In gm-gmp.Dll String a_string
Ret = gmp_sqrtrem("7")  && sqrt("7") = 3
?? gmp_todec(Ret)


? "根开方函数:"  && 计算一个数的n次根。结果舍入到零
*!*    function gmp_root(a_string:string;n_string:string):string
Declare String gmp_root In gm-gmp.Dll String a_string, String n_string
Ret = gmp_root("8", "2")
?? gmp_todec(Ret)  && 


? "根开方余数:"  && 计算一个数的n次根的剩余部分
*!*    function gmp_rootrem(a_string:string;n_string:string):string
Declare String gmp_rootrem In gm-gmp.Dll String a_string, String n_string
Ret = gmp_rootrem("8", "2")
?? gmp_todec(Ret)  && 


? "比较函数======================================"
? "比较大小  :"  && 1 = 大于;-1 = 小于;0 = 等于
*!*    function gmp_compare(a_string:string;b_string:string):real
Declare Double gmp_compare In gm-gmp.Dll String a_string, String b_string
Ret = gmp_compare("4", "2")  && 1
?? Ret


? "绝对值比较:"  && 1 = 大于;-1 = 小于;0 = 等于
*!*    function gmp_abscompare(a_string:string;b_string:string):real
Declare Double gmp_abscompare In gm-gmp.Dll String a_string, String b_string
Ret = gmp_abscompare("-4", "2")  && 1
?? Ret


? "正负数判别:"  && 1 = 正数;-1 = 负数;0 = 零
*!*    function gmp_sign(a_string:string):real
Declare Double gmp_sign In gm-gmp.Dll String a_string
Ret = gmp_sign("-4")  && -1
?? Ret


? "偶数判别  :"  && 1 = 偶数;0 = 奇数
*!*    function gmp_even(a_string:string):real
Declare Double gmp_even In gm-gmp.Dll String a_string
Ret = gmp_even("4")  && 1
?? Ret


? "奇数判别  :"  && 1 = 奇数;0 = 偶数
*!*    function gmp_odd(a_string:string):real
Declare Double gmp_odd In gm-gmp.Dll String a_string
Ret = gmp_odd("5")  && 1
?? Ret


? "数论函数======================================"
? "质数函数  :"  && 2 = 质数(素数);0 = 不是质数;1 = 不确定
*!*    function gmp_probab_prime(a_string:string;reps:real):real
Declare Double gmp_probab_prime In gm-gmp.Dll String a_string, Float real
Ret = gmp_probab_prime("17")  && 2
?? Ret


? "下一个质数:"  && 2 = 质数;0 = 不是质数;1 = 不确定
*!*    function gmp_probab_nextprime(a_string:string):string
Declare String gmp_probab_nextprime In gm-gmp.Dll String a_string
Ret = gmp_probab_nextprime("123")
?? gmp_todec(Ret)  && 127


? "最大公因数"
*!*    function gmp_gcd(a_string:string;b_string:string):string
Declare String gmp_gcd In gm-gmp.Dll String a_string, String b_string
Ret = gmp_gcd("12", "4")
?? gmp_todec(Ret)  && 4


? "最小公倍数"
*!*    function gmp_lcm(a_string:string;b_string:string):string
Declare String gmp_lcm In gm-gmp.Dll String a_string, String b_string
Ret = gmp_lcm("12", "6")
?? gmp_todec(Ret)  && 12


? "因子阶乘  :"  && 计算n的阶乘
*!*    function gmp_factorial(n_string:string):string
Declare String gmp_factorial In gm-gmp.Dll String n_string
Ret = gmp_factorial("3")
?? gmp_todec(Ret)  && 1 * 2 * 3 = 6


? "Fibonacci :"  && 计算n阶Fibonacci数。
*!*    function gmp_fibonacci(n_string:string):string
Declare String gmp_fibonacci In gm-gmp.Dll String n_string
Ret = gmp_fibonacci("6")
?? gmp_todec(Ret)  && 8


? "杂类函数======================================"
? "最小值:"
*!*    function gmp_min(a_string:string;b_string:string):string
Declare String gmp_min In gm-gmp.Dll String a_string, String b_string
Ret = gmp_min("3", "10")
?? gmp_todec(Ret)  && 3


? "最大值:"
*!*    function gmp_max(a_string:string;b_string:string):string
Declare String gmp_max In gm-gmp.Dll String a_string, String b_string
Ret = gmp_max("3", "10")
?? gmp_todec(Ret)  && 10


? "=============================================="
*!*    Declare Double gmp_probab_prime In gm-gmp.Dll String a_string, Float real
*!*    Declare Double gmp_real         In gm-gmp.Dll String a_string, Float real
*!*    ? gmp_probab_prime("12")
*!*    ? gmp_real("234")


*!*    Declare Double gmp_probab_prime In gm-gmp.Dll String a_string, Double real
*!*    Declare Double gmp_real         In gm-gmp.Dll String a_string, Double real
*!*    ? gmp_probab_prime("127", 0)
*!*    ? gmp_real("234", 0)


Clear Dlls

回马枪 2014-10-11
  • 打赏
  • 举报
回复
这样吧 我们直奔主题 GNU GMP 是一个开源的高精度大数库 官网在:https://gmplib.org/ 官网发布的是静态库 VFP 只能使用 Dll 方式的动态库 CSDN 等很多热心人把它编译成了 Dll 版 有不同的编译版 比如:GMP.Dll、GM-GMP.Dll、libgmp-510.dll 等等 这些网站有 Dll 和中文资料下载的: GMP中文简介.pdf http://download.csdn.net/detail/beryl26/5061720 GMP,c语言大数开发,中文资料和测试 http://download.csdn.net/download/stickney/4102152 最新gmp 5.1.0 编译好的dll windows下使用 http://download.csdn.net/download/G_Spider/2970355 最后的问题是: 如何调用这些 DLL 最好有 VFP 的几个示例 谢谢你(们)
都市夜猫 2014-10-10
  • 打赏
  • 举报
回复
vfp 没有结构类型,一直饱受诟病,有人写过结构类,来模拟结构类型,不过都不算很方便,且表现能力有限 如果不是大量使用结构,简单的用字符串来模拟,还是可以解决一些问题的 上面的 MPZ 结构这样来定义: mpz = bintoc(mp_alloc, '4rs') + bintoc(mp_size, '4rs') + bintoc(mp_limb, '4rs') 返回后的结果,这样来拆分得到个成员的值: mp_alloc = ctobin(substr(mpz,1,4), '4rs') mp_size = ctobin(substr(mpz,5,4), '4rs') mp_limb = ctobin(substr(mpz,9,4), '4rs') MPQ 结构重复一次即可: mpz1 = bintoc(mp_alloc1, '4rs') + bintoc(mp_size1, '4rs') + bintoc(mp_limb1, '4rs') mpz2 = bintoc(mp_alloc2, '4rs') + bintoc(mp_size2, '4rs') + bintoc(mp_limb2, '4rs') mpq = mpz1 + mpz2 拆分: mpz1 = substr(mpq, 1, len(mpz1)) mpz2 = substr(mpq, 1+len(mpz1), len(mpz2)) mpz1 和 2 继续拆分同上

2,723

社区成员

发帖
与我相关
我的任务
社区描述
VFP,是Microsoft公司推出的数据库开发软件,用它来开发数据库,既简单又方便。
社区管理员
  • VFP社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧