Advertisement
theosib

Rounding error with doubles

May 26th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. run:
  2. Correct entity width: 0.6
  3.  
  4. *** First we move an entity around the way vanilla code does and see the problem...
  5.  
  6. Starting out at some place in the world:
  7.  
  8. Xmin=1.8,Xmax=2.4,w=0.5999999999999999
  9. Xcenter=2.1
  10.  
  11. Have the entity get shoved around for a while...
  12.  
  13. Shifting Xmin and Xmax both by:
  14. +0.01562500000000011
  15. +0.015625000000000114
  16. +0.01562500000000011
  17. +0.015625000000000114
  18. +0.01562500000000011
  19. +0.015625000000000114
  20. +0.01562500000000011
  21. +0.015625000000000114
  22. +0.01562500000000011
  23. +0.015625000000000114
  24. +0.01562500000000011
  25. +0.015625000000000114
  26. +0.015625000000000003
  27. -0.015625000000000222
  28. +0.015625000000000003
  29. +0.015625000000000222
  30.  
  31. Finally ended up at:
  32. Xmin=2.0187500000000034,Xmax=2.6187499999999995,w=0.5999999999999961
  33. Xcenter=2.3187500000000014
  34. new width is 0.5999999999999961, 3.885780586188048E-15 smaller than it should be
  35.  
  36. Imagine it got shoved one last time, against a wall to the west:
  37. New bounding box and computed center:
  38. Xmin=2.0,Xmax=2.599999999999996,w=0.5999999999999961
  39. Xcenter=2.299999999999998
  40.  
  41. Only the center is saved to disk. When reloaded, we get this:
  42. Reloaded center and computed faces:
  43. Xcenter=2.299999999999998
  44. Xmin=1.999999999999998,Xmax=2.599999999999998,w=0.5999999999999999
  45. The west face now intersects the wall by -1.9984014443252818E-15
  46.  
  47. Imagine instead it got shoved one last time, against a wall to the east:
  48. New bounding box and computed center:
  49. Xmin=2.400000000000004,Xmax=3.0,w=0.5999999999999961
  50. Xcenter=2.700000000000002
  51.  
  52. Only the center is saved to disk. When reloaded, we get this:
  53. Reloaded center and computed faces:
  54. Xcenter=2.700000000000002
  55. Xmin=2.400000000000002,Xmax=3.0000000000000018,w=0.5999999999999996
  56. The east face now intersects the wall by 1.7763568394002505E-15
  57.  
  58.  
  59. *** Now try again with code that maintains consistency between bounds and center...
  60.  
  61. Starting out at some place in the world:
  62.  
  63. Xmin=1.8,Xmax=2.4,w=0.5999999999999999
  64. Xcenter=2.1
  65.  
  66. Have the entity get shoved around for a while...
  67.  
  68. Shifting Xmin and Xmax both by:
  69. +0.01562500000000011
  70. +0.01562500000000011
  71. +0.01562500000000011
  72. +0.01562500000000011
  73. +0.01562500000000011
  74. +0.01562500000000011
  75. +0.01562500000000011
  76. +0.01562500000000011
  77. +0.01562500000000011
  78. +0.01562500000000011
  79. +0.01562500000000011
  80. +0.01562500000000011
  81. +0.015625000000000003
  82. -0.015625000000000222
  83. +0.015625
  84. -0.015625000000000226
  85. +0.015625000000000003
  86. -0.015625000000000222
  87. +0.015625
  88. -0.015625000000000226
  89. +0.015625000000000003
  90. -0.015625000000000222
  91. +0.015625
  92. -0.015625000000000226
  93. +0.015625000000000003
  94. -0.015625000000000222
  95. +0.015625
  96. -0.015625000000000226
  97. +0.015625000000000003
  98. -0.015625000000000222
  99. +0.015625
  100. -0.015625000000000226
  101. +0.015625000000000003
  102. -0.015625000000000222
  103. +0.015625
  104. -0.015625000000000226
  105. +0.015625000000000003
  106. -0.015625000000000222
  107. +0.015625
  108. -0.015625000000000226
  109. +0.015625000000000003
  110. -0.015625000000000222
  111. +0.015625
  112. -0.015625000000000226
  113. +0.015625000000000003
  114. -0.015625000000000222
  115. +0.015625
  116. -0.015625000000000226
  117. +0.015625000000000003
  118. -0.015625000000000222
  119. +0.015625
  120. -0.015625000000000226
  121. +0.015625000000000003
  122. -0.015625000000000222
  123. +0.015625
  124. -0.015625000000000226
  125. +0.015625000000000003
  126. -0.015625000000000222
  127. +0.015625
  128. -0.015625000000000226
  129. +0.015625000000000003
  130. -0.015625000000000222
  131. +0.015625
  132. -0.015625000000000226
  133. +0.015625000000000003
  134. -0.015625000000000222
  135. +0.015625
  136. -0.015625000000000226
  137. +0.015625000000000003
  138. -0.015625000000000222
  139. +0.015625
  140. -0.015625000000000226
  141. +0.015625000000000003
  142. -0.015625000000000222
  143. +0.015625
  144. -0.015625000000000226
  145. +0.015625000000000003
  146. -0.015625000000000222
  147. +0.015625
  148. -0.015625000000000226
  149. +0.015625000000000003
  150. -0.015625000000000222
  151. +0.015625
  152. -0.015625000000000226
  153. +0.015625000000000003
  154. -0.015625000000000222
  155. +0.015625
  156. -0.015625000000000226
  157. +0.015625000000000003
  158. -0.015625000000000222
  159. +0.015625
  160. -0.015625000000000226
  161. +0.015625000000000003
  162. -0.015625000000000222
  163. +0.015625
  164. -0.015625000000000226
  165. +0.015625000000000003
  166. -0.015625000000000222
  167. +0.015625
  168. -0.015625000000000226
  169.  
  170. Finally ended up at:
  171. Xmin=1.9874999999999805,Xmax=2.5874999999999804,w=0.5999999999999999
  172. Xcenter=2.2874999999999805
  173. new width is 0.5999999999999999, 1.1102230246251565E-16 smaller than it should be
  174.  
  175. Imagine it got shoved one last time, against a wall to the west:
  176. New bounding box and computed center:
  177. Xmin=1.0,Xmax=1.6,w=0.6000000000000001
  178. Xcenter=1.3
  179.  
  180. Only the center is saved to disk. When reloaded, we get this:
  181. Reloaded center and computed faces:
  182. Xcenter=1.3
  183. Xmin=1.0,Xmax=1.6,w=0.6000000000000001
  184. The west face now intersects the wall by 0.0
  185.  
  186. Imagine instead it got shoved one last time, against a wall to the east:
  187. New bounding box and computed center:
  188. Xmin=2.4000000000000004,Xmax=3.0,w=0.5999999999999996
  189. Xcenter=2.7
  190.  
  191. Only the center is saved to disk. When reloaded, we get this:
  192. Reloaded center and computed faces:
  193. Xcenter=2.7
  194. Xmin=2.4000000000000004,Xmax=3.0,w=0.5999999999999996
  195. The east face now intersects the wall by 0.0
  196. BUILD SUCCESSFUL (total time: 0 seconds)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement