|
| 28 Mar 2013 11:10 PM |
for n=1,3,0.1 do print(n, 2-n, 2-n==0.1) end
>1.9 0.099999999999999 false
wat up wit dat |
|
|
| Report Abuse |
|
|
xSIXx
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 9202 |
|
|
| 28 Mar 2013 11:12 PM |
function round(num, r) return math.floor(num/r+.5)*r end
round(num, 0.1 or however accurate you are intervalling) |
|
|
| Report Abuse |
|
|
Anaminus
|
  |
 |
| Joined: 29 Nov 2006 |
| Total Posts: 5945 |
|
|
| 28 Mar 2013 11:14 PM |
Floatin points, man. If you don't like it, do dis:
for n=10,30,1 do print(n/10) end |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2013 11:20 PM |
| Now I'm going to be paranoid about operating on decimals for the next two months. Thanks, roblox. |
|
|
| Report Abuse |
|
|
|
| 28 Mar 2013 11:22 PM |
| Technology Lesson 1: Computers are very bad with decimals. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 29 Mar 2013 06:15 AM |
| You shud move on to use values representable in binary :3 |
|
|
| Report Abuse |
|
|
SN0X
|
  |
| Joined: 24 Oct 2011 |
| Total Posts: 7277 |
|
|
| 29 Mar 2013 07:02 AM |
| just do math with strings when ur doing stuff like that |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 07:42 AM |
'Thanks, roblox.'
Blame Lua, not Roblox. |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 29 Mar 2013 08:22 AM |
| http://www.exploringbinary.com /double-rounding-errors-in-floating-point-conversions/ |
|
|
| Report Abuse |
|
|
Validar
|
  |
| Joined: 15 Mar 2013 |
| Total Posts: 276 |
|
|
| 29 Mar 2013 10:16 AM |
@pre >Lua >RBX.Lua Blame ROBLOX for editing off of Lua. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 10:33 AM |
| RBX.Lua is an environment and Roblox have not adapted Lua except removing the ability to load bytecode through loadstring. It is not the fault of Roblox, at all. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 10:40 AM |
Here's something I found that you guys might find interesting:
"Interestingly, the launch failure of the Ariane 5 rocket, which exploded 37 seconds after liftoff on June 4, 1996, occurred because of a software error that resulted from converting a 64-bit floating point number to a 16-bit integer. The value of the floating point number happened to be larger than could be represented by a 16-bit integer. The overflow wasn't handled properly, and in response, the computer cleared its memory. The memory dump was interpreted by the rocket as instructions to its rocket nozzles, and an explosion resulted." |
|
|
| Report Abuse |
|
|
Waffle3z
|
  |
| Joined: 15 Apr 2011 |
| Total Posts: 266 |
|
|
| 29 Mar 2013 10:41 AM |
| This is also annoying in GUIs. I set its position to 2.5, stop changing it to 2.49999997 |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 29 Mar 2013 12:05 PM |
| That's just Lua's floating point precision. 2.5 isn't 2.5 to the computer; it's either 2.49999997 or 2.50000001. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 12:06 PM |
| king: Which is why we have build tests and debugging and srsly should of NASA noticed that |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 12:07 PM |
| I believe the GUI thing is the Scale automatically going to the nearest pixel. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2013 12:07 PM |
| 2.5 should be solid though. In binary it's written as 10.1 |
|
|
| Report Abuse |
|
|
digpoe
|
  |
| Joined: 02 Nov 2008 |
| Total Posts: 9092 |
|
|
| 29 Mar 2013 12:10 PM |
| I know. But it's just how the creator of Lua decided how it was to be. It could also be the C++ base behind Lua, but I don't code in C++ so I don't know that much. |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 29 Mar 2013 12:23 PM |
| In python docs there's an article called "Floating Point Arithmetic: Issues and Limitations". You should read it, also, why has nobody written an article about this in the roblox wiki? |
|
|
| Report Abuse |
|
|
lombardo2
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 29 Mar 2013 12:26 PM |
| @digpoe: That's not lua, that's the IEEE Standard 754, unless you interpret the exponent as base 10, you are going to get this rounding errors. |
|
|
| Report Abuse |
|
|