| Home CBM ASCII-X BASIC Disk Commands Enter RUN mode Program Format Secret Variables Variable Format Expressions Keywords (divide) (equal) (less) (minus) (more) (multiply) (plus) (power) Abs And Append Asc Atn Auto Backup Bank Begin Bend Bload Boot Box Bsave Bump Catalog Char Chr Circle Close Clr Cmd Collect Collision Color Concat Cont Copy Cos Data Dclear Dclose Dec Def Delete Dim Directory Dispose Dload Do Dopen Draw Ds Ds string Dsave Dverify El Else End Envelope Er Err Exit Exp Fast Fetch Filter Fn For Fre Get Get num Getkey Go Gosub Goto Graphic Gshape Header Help Hex If Input Input num Instr Int Joy Key Left Len Let List Load Locate Log Loop Mid Monitor Movspr New Next Not Off On Open Or Paint Peek Pen Pi Play Pointer Poke Pos Pot Print num Pudef Quit Rclr Rdot Read Record Rem Rename Renumber Restore Resume Return Rgr Right Rlum Rnd Rreg Rspcolor Rsppos Rsprite Run Rwindow Save Scale Scnclr Scratch Sgn Sin Sleep Slow Sound Spc Sprcolor Sprdef Sprite Sprsav Sqr Sshape St Stash Step Stop Str Swap Sys Tab Tan Tempo Then Ti Ti string To Trap Troff Tron Until Using Usr Val Verify Vol Wait While Width Window Xor Syntax Tokens C128 D64plus Disk Escape Codes Hardware PCxface PETSCII Pet2asc Futurama IBM PC-AT Contact Games Glossary Hall of fame Hall of shame Miscellaneous Privacy policy Programming Twisty puzzles |
INT ( value )
Calculate the "floor" of a number.
The INT function returns the largest integer less than or equal to the supplied value. For positive numbers, this is like chopping off any fractional part (it is never rounded up). For negative numbers that are not already integers, the next lower integer is returned. Hopefully the examples below will clarify, but you might also like to think of this as "round towards negative infinity." * Like most BASIC math functions and operators, the INT function actually returns the result as a floating-point "type" of number (in terms of BASIC numeric types). However it is gauranteed to be a mathematical integer; that is, with no digits (or all zeros) after the decimal point. BASIC limits several things to be a certain kind of integer, but this function is generally NOT useful with them. Where BASIC limits things to integers, it will automatically convert a floating-point value to an integer automatically (just as if this function were used). Because this function is called automatically in those cases, INT is not needed. The reason I mention this is because the result may not be acceptable in some cases where an integer is required. For example, to store a value in an integer-type variable, the result must be -32768 to +32767; but there is no gaurantee the result will be in that range. Similarly, some BASIC statements and functions want an unsigned integer (0 to 65535) or a byte (0 to 255). INT can be used to round numbers with a little trick (see examples). It is also useful to calculate the remainder after division (so called modulus). You will get TYPE MISMATCH ERROR with a string value. Example with simple positives and negitves (notice the numbers are not rounded):
Examples of rounding (just add 0.5):
Examples of remainder (modulus):
© H2Obsession, 2014 |