/*My header (as I've been using it, in this blog), abridged*/ #include<stdint.h> typedef int32_t t4s; typedef float t4f; typedef double t8f; #define ih else #include<math.h> static t4s const __cE=0x0A; static t4s const __cF=0x15; static t4s const __cB=0x300; static t4f const __cL=log(2.F); static t4s _fAPkF4(t4f p){t4s S; if(p<0){S=0x80000000;p=-p;}ih{S=0;} t4s E=(t4s)floor(log(p)/__cL+.001F);/*+epsilon*/ t4s M=(t4s)rint(ldexp(p,(__cF-1)-E)); E=(E+__cB)<<__cF;return S|E|M;} static t4f _fBPkF4(t4s p){t8f M; if(p&0x80000000){M=-(p&0x1FFFFF);}ih{M=p&0x1FFFFF;} t4s E=(p&0x7FE00000L)>>__cF; return(t4f)ldexp(M,E-(__cF-1)-__cB);} #include<iostream> int main(){t4s l; l=_fAPkF4(+1.00F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(+0.75F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(+0.50F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(+0.25F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(+0.00F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(-0.25F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(-0.50F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(-0.75F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; l=_fAPkF4(-1.00F);std::cout<<l<<" "<<_fBPkF4(l)<<std::endl; std::cout<<std::endl<<std::endl<<std::endl; return 0;}
Output:
1611661312 1 1610088448 0.75 1609564160 0.5 1607467008 0.25 1610612736 0 -540016640 -0.25 -537919488 -0.5 -537395200 -0.75 -535822336 -1
No comments:
Post a Comment