Difference between revisions of "Talk:Floor"
Jump to navigation
Jump to search
imported>DragoonWraith |
imported>Scruggs (int = float -> truncate) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 8: | Line 8: | ||
:According to [[:Category:Variables|this page]] all integer variables are rounded to the nearest integer. So 1.9 would be rounded to 2. Instead you want to round it to 1, so how about subtracting 0.5 before putting it into a short: | :According to [[:Category:Variables|this page]] all integer variables are rounded to the nearest integer. So 1.9 would be rounded to 2. Instead you want to round it to 1, so how about subtracting 0.5 before putting it into a short: | ||
<dl><dd> | |||
short flooredInt | short flooredInt | ||
float decimalValue | float decimalValue | ||
Line 18: | Line 18: | ||
set decimalValue to 2.0 | set decimalValue to 2.0 | ||
set flooredInt to decimalValue - 0.5 | set flooredInt to decimalValue - 0.5 | ||
;; rounding 1.5 to the nearest integer gives 2 | ;; rounding 1.5 to the nearest integer gives 2 | ||
</dl> | |||
:--[[User:Qazaaq|Qazaaq]] 17:26, 18 October 2008 (EDT) | :--[[User:Qazaaq|Qazaaq]] 17:26, 18 October 2008 (EDT) | ||
Line 38: | Line 39: | ||
::That template is '''awesome''', Qazaaq, by the way. | ::That template is '''awesome''', Qazaaq, by the way. | ||
::[[User:DragoonWraith|<span style="font-family: Oblivion, Daedric Runes; size=2;">D</span>ragoon <span style="font-family: Oblivion, Daedric Runes; size=2;">W</span>raith]] [[User_talk:DragoonWraith|<span style="font-family: Oblivion, Daedric Runes; size=2;">TALK</span>]] 17:41, 18 October 2008 (EDT) | ::[[User:DragoonWraith|<span style="font-family: Oblivion, Daedric Runes; size=2;">D</span>ragoon <span style="font-family: Oblivion, Daedric Runes; size=2;">W</span>raith]] [[User_talk:DragoonWraith|<span style="font-family: Oblivion, Daedric Runes; size=2;">TALK</span>]] 17:41, 18 October 2008 (EDT) | ||
:::Unlikely and wrong. Assigning a float value to an integer truncates. Possible exception for global variables. [[User:Scruggs|Scruggs]] 21:20, 21 October 2008 (EDT) | |||
Thanks guys, that's a big help ^_^ | |||
[[User:Morerunes|morerunes]] 23:54, 18 October 2008 (EDT) |
Latest revision as of 20:20, 21 October 2008
Floor without OBSE?[edit source]
While I personally think everyone should get OBSE, some people would rather not. I was trying to do the floor function without OBSE by setting and reading variables, but I can't think of a way to do it.
anybody have any ideas?
morerunes 15:50, 18 October 2008 (EDT)
- According to this page all integer variables are rounded to the nearest integer. So 1.9 would be rounded to 2. Instead you want to round it to 1, so how about subtracting 0.5 before putting it into a short:
- short flooredInt float decimalValue set decimalValue to 1.9 set flooredInt to decimalValue - 0.5 ;; rounding 1.4 to the nearest integer gives 1 set decimalValue to 2.0 set flooredInt to decimalValue - 0.5 ;; rounding 1.5 to the nearest integer gives 2
- --Qazaaq 17:26, 18 October 2008 (EDT)
- It strikes me as incredibly unlikely that setting a short to a float results in rounding rather than truncation. Given the very old (read: out-of-date) nature of that article, I'd test that. If it doesn't round, then just setting a short to a float value will automatically floor it.
- But regardless, using Modulo would eliminate dependence on the particular implementation there:
short flooredInt float decimalValue set decimalValue to 1.9 set flooredInt to decimalValue - ( decimalValue % 1 ) ;; 1.9 - 0.9 = 1 set decimalValue to 2.0 set flooredInt to decimalValue - ( decimalValue % 1 ) ;; 2.0 - 0 = 2
- That template is awesome, Qazaaq, by the way.
- Dragoon Wraith TALK 17:41, 18 October 2008 (EDT)
- Unlikely and wrong. Assigning a float value to an integer truncates. Possible exception for global variables. Scruggs 21:20, 21 October 2008 (EDT)
Thanks guys, that's a big help ^_^
morerunes 23:54, 18 October 2008 (EDT)