What should an int() function do?



Greetings:

I would think that an int() function should return the integer part of a number by simply erasing the part after the decimal place:

int(0.5)=0
int(1.2)=1
int(1)=1
int(-0.4)=0
int(-2.3)=-2

A floor() function shuold always return the integer less than or equal to its argument:

floor(0.5)=0
floor(1.2)=1
floor(1)=1
floor(-0.4)=-1
floor(-2.3)=-3

And a ceiling() function should return the integer greater or equal to its argument:

ceiling(0.5)=1
ceiling(1.2)=2
ceiling(1)=1
ceiling(-0.4)=0
ceiling(-2.3)=-2

Thus the int() function could be defined as (in math notation, not computer code):

int(x) = {
floor(x), x>=0
ceiling(x), x<0 }

But my TI-89 calculator seems to do this:

int(x) = floor(x)

Is this a crummy implementation of int() ?




-- Good day!

________________________________________
Christopher R. Carlen
Principal Laser&Electronics Technologist
Sandia National Laboratories CA USA
crcarleRemoveThis@xxxxxxxxxxxxxxx
NOTE, delete texts: "RemoveThis" and
"BOGUS" from email address to reply.
.



Relevant Pages

  • Re: years later DeprecationWarning
    ... math.floor returns a float, not an int. ... No it doesn't, or rather, intis only equivalent to floor() if you limit ... "Returns the maximum integer less than or equal to x" ...
    (comp.lang.python)
  • Re: Converting milliseconds to seconds
    ... }} use int for rounding" - any rounding method has the same problem. ... Neither floor, nor ceil does the same as int. ... floor: round to -inf. ...
    (comp.lang.perl.misc)
  • Re: value of ((int)0.7) and ((int)-0.7)
    ... floor() was clearly mentioned by the OP in the post I was replying to. ... rounding of x would behave on straight conversion to int. ... The integer division is an aside which which the OP and other readers ... not match the rounding of conversion from floating point to an integer ...
    (comp.lang.c)
  • Re: ruler
    ... for some deeper explanation (or pointer to relevant documents such as ... void Rule(int Ruler[], int Left, int Right, int Height) ... It might be because I take the lift up 1 floor to get to the 1st ...
    (comp.lang.c)
  • Re: Converting milliseconds to seconds
    ... }} use int for rounding" - any rounding method has the same problem. ... Neither floor, nor ceil does the same as int. ... floor: round to -inf. ...
    (comp.lang.perl.misc)