首页 > 代码库 > wine中complex::pow 补丁的实现

wine中complex::pow 补丁的实现

我发了一个wine的补丁,实现complex::pow的部分重载:http://source.winehq.org/patches/data/104267

HongQian帮我在irc上问了Piotr对这个补丁的看法,他说:
“it generally looks ok but it‘s possible to implement it with better
precision, so I‘m not sure what to think about it”

我想了想发现,其实我们在实现complex::pow
在指数为实整数的情况下的重载的时候,没有必要先把实整数转换为复数的。一开始我是为了简化补丁的难度,就建议参考最像的函数进行实现,没有充分考虑到精度的问题。”

我去查了一些资料,发现,以前初学C\C++用pow函数的时候有点疑惑,为什么参数int要转化成double,以为是系统规定的,当时为了编译能过就用了转换了,也没有看源代码的想法。今天才知道,原来是考虑到那么几个问题(overflow、负数次幂的结果)等才用double的,而且还提高了复用,感觉设计得很好~(除了给人一点点confuse)


然后我做了测试,这是在win下的结果:

pow(complex_float= (3.14159f, 0), 3):  (31.006203,0.000000)
complex_translation:  (31.006201,0.000000)
*******************************************************
pow(complex_float= (32.1234f, 0), 6):  (1098826752.000000,0.000000)
complex_translation:  (1098826624.000000,0.000000)
*******************************************************
pow(complex_float= (7.12f, 0), 6):  (130280.640625,0.000000)
complex_translation:  (130280.648438,0.000000)


*******************Now is complex_double************************************


pow(complex_double= (3.14159/2, 0), 3):  (3.875775, 0.000000)
double_complex_translation:  (3.875775, 0.000000)
*******************************************************
pow(complex_double= (32.12345678, 0), 13):  (38787300223012692000.000000, 0.000000)
double_complex_translation:  (38787300223012684000.000000, 0.000000)
*******************************************************
pow(complex_double= (7.12, 0), 33):  (13546895790785450000000000000.000000, 0.000000)
double_complex_translation:  (13546895790785442000000000000.000000, 0.000000)
*******************************************************

现在决定用手写的底数为复数而指数为整数次幂的pow来解决