Floor.htm 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>Floor# ( y# )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. y = any number
  13. </td>
  14. </tr>
  15. </table>
  16. <h1>Description</h1>
  17. <table>
  18. <tr>
  19. <td>
  20. Rounds downward, i.e. in the direction of -Infinity. <br />
  21. <br />
  22. It is a common mistake to think this simply sets everything after the decimal point to zero. <br />
  23. But this is true only for positive numbers: <br />
  24. <br />
  25. Floor( 1.75 ) ....... 1.0 <br />
  26. Floor( -1.75 ) .... -2.0 <br />
  27. <br />
  28. See also Ceil and Int for other types of rounding.
  29. </td>
  30. </tr>
  31. </table>
  32. <h1><a href=../2d_examples/Floor.bb>Example</a></h1>
  33. <table>
  34. <tr>
  35. <td>
  36. ; Ceil / Floor / Int example, three kinds of rounding. <br />
  37. <br />
  38. ; Move mouse. Escape quits. <br />
  39. <br />
  40. Graphics 640, 480 <br />
  41. <br />
  42. Const KEY_ESC = 1 <br />
  43. <br />
  44. SetBuffer BackBuffer() <br />
  45. Origin 320, 240 <br />
  46. <br />
  47. MoveMouse 320, 240 : HidePointer <br />
  48. <br />
  49. While Not KeyDown( KEY_ESC ) <br />
  50. <br />
  51. Cls <br />
  52. <br />
  53. my = MouseY() - 240 <br />
  54. Color 100, 100, 0 <br />
  55. Line -320, my, 319, my <br />
  56. <br />
  57. DrawNumberLine <br />
  58. <br />
  59. y# = Float( -my ) / 32 <br />
  60. <br />
  61. Text 100, 50, " y = " + y <br />
  62. Text 100, 70, " Ceil( y ) = " + Ceil( y ) <br />
  63. Text 100, 90, " Floor( y ) = " + Floor( y ) <br />
  64. Text 100, 110, " Int( y ) = " + Int( y ) <br />
  65. <br />
  66. Flip <br />
  67. <br />
  68. Wend <br />
  69. End <br />
  70. <br />
  71. Function DrawNumberLine( ) ; vertical line with numeric labels <br />
  72. <br />
  73. Color 255, 255, 255 <br />
  74. Line 0, -240, 0, 239 <br />
  75. <br />
  76. For n = -7 To 7 <br />
  77. yn = -32 * n <br />
  78. Line -2, yn, 2, yn <br />
  79. Text -30, yn - 6, RSet( n, 2 ) <br />
  80. Next <br />
  81. <br />
  82. End Function
  83. </td>
  84. </tr>
  85. </table>
  86. <br>
  87. <a target=_top href=../index.htm>Index</a><br>
  88. <br>
  89. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=Floor&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  90. </html>