整数移位代替法处理浮点

整数移位代替法处理浮点

mathFP是一个java上的开发包,利用它,可以用整形变量来处理浮点问题。
传统上,我们采用整数放大10的n次方倍后,进行运算,计算完成后,再缩小10的n次方。换算出结果。
而mathFP就是利用这个思路,不过它不是扩大10的n次方倍,而是扩大2的n次方倍,这样,就可以很方便的利用开发语言中的移位指令做放大缩小处理,大大的提高了运算的速度。
具体来说,一个整数是这样变成FP支持的数的(_fbits是2进制移动的位数)
public static int toFP(int i)
{return i << _fbits;}
如果是小数点以后的数字想变成支持的数,可以这样做:
0.25 -〉 25 << _fbits / 100
那么,得到fp数后,加、减、乘、除的运算分别这样做(假设要运算的fp数为i,j)
i + j;
i – j;
i * j << _fbits;
(i << _fbits) / j << _fbits;
当然,mathFP的处理方法要严谨得多,不够大概的原理就是这样。
Enjoy it!

2 thoughts on “整数移位代替法处理浮点

  1. Hi,Do you need advertising displays, digital signages, mp4 advertisement players, SD card players and advertisement LCD displays? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[i

  2. wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling
    wow power leveling -229286606109257

Leave a Reply

Your email address will not be published. Required fields are marked *