Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. const size_t initialSize=24;
  2. const size_t sizeForMult1=initialSize+initialSize;
  3. const size_t finalSize=sizeForMult1+initialSize;
  4. class imSoHuge{
  5. public:
  6. bool isNegative;
  7. uint8_t r[finalSize];
  8. void load(float v){
  9. isNegative=false;
  10. for(size_t p=0;p<finalSize;p++)r[p]=0;
  11. union{
  12. uint8_t b[4];
  13. uint32_t u;
  14. float f;
  15. } reunion;
  16. reunion.f=v;
  17. if((reunion.b[3]&0x80) != 0x00)isNegative=true;
  18. uint32_t m, eu;
  19. eu=reunion.u<<1; //get rid of the sign;
  20. eu>>=24;
  21. m=reunion.u&(0x007fffff);
  22. if(eu==0){//zero or denormal
  23. if(m==0)return; //zero
  24. }else{
  25. m|=(0x00800000); //implicit leading one if it's not denormal
  26. }
  27. int32_t e=(int32_t)eu-127; //exponent is now in [e]. Debiased (does this word exists?)
  28. reunion.u=m;
  29. r[finalSize-1]=reunion.b[3];
  30. r[finalSize-2]=reunion.b[2];
  31. r[finalSize-3]=reunion.b[1];
  32. r[finalSize-4]=reunion.b[0];
  33. rollArrayRight(r, finalSize, e-(sizeForMult1*8)); //correct position for fixed-point
  34. }
  35. explicit imSoHuge(float v){
  36. load(v);
  37. }
  38. };
  39.  
  40. float a[]={0.0097905760, 0.0223784577, 0.9997016787};
  41.  
  42. float b[]={0.8248013854, 0.4413521587, 0.3534274995};
  43.  
  44. float c[]={0.4152690768, 0.3959976136, 0.8189856410};
  45.  
  46. float fTripleProduct(float*a, float*b, float*c){
  47. float crossAB[3];
  48. crossAB[0]=(a[1]*b[2])-(a[2]*b[1]);
  49. crossAB[1]=(a[2]*b[0])-(a[0]*b[2]);
  50. crossAB[2]=(a[0]*b[1])-(a[1]*b[0]);
  51. float tripleP=(crossAB[0]*c[0])+(crossAB[1]*c[1])+(crossAB[2]*c[2]);
  52. return tripleP;
  53. }
  54.  
  55. imSoHuge tripleProduct(float*a, float*b, float*c){
  56. imSoHuge crossAB[3];
  57. crossAB[0]=(imSoHuge(a[1])*imSoHuge(b[2]))-(imSoHuge(a[2])*imSoHuge(b[1]));
  58. crossAB[1]=(imSoHuge(a[2])*imSoHuge(b[0]))-(imSoHuge(a[0])*imSoHuge(b[2]));
  59. crossAB[2]=(imSoHuge(a[0])*imSoHuge(b[1]))-(imSoHuge(a[1])*imSoHuge(b[0]));
  60. imSoHuge tripleP=(crossAB[0]*imSoHuge(c[0]))+(crossAB[1]*imSoHuge(c[1]))+(crossAB[2]*imSoHuge(c[2]));
  61. return tripleP;
  62. }
  63.  
  64. 0 0 0 4 46 b9 4 69 39 3f 53 b8 19 e0 ...
  65.  
  66. 0 0 0 4 46 b9 4 85 93 82 df ba 7d 80 ...
  67.  
  68. Using class: second result is greater
  69. casting to float:
  70. first reasult: 1.336331e-001
  71. second result: 1.336331e-001
  72. as floats, the results are the same: 1.336331e-001
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement