Re: simple eurphoria question
Mark K. Akita wrote:
>
> Chris Bensler wrote:
> >
> > Mark K. Akita wrote:
> > >
> > > Hi John,
> > >
> > > This function seems to work as well for converting atom to integer.
> > >
> > > }}}
<eucode>
> > >
> > > function int(atom a)
> > >
> > > return floor(a)+(a<0)
> > >
> > > end function
> > >
> > > </eucode>
{{{
> > >
> > > Good luck!
> > >
> > > Mark K. Akita
> > > <a
> > > href="http://marksarts.blogspot.com/">http://marksarts.blogspot.com/</a>
> >
> > That's what I thought Mark, but it's incorrect. :)
> > Try with this set of numbers: 1, 1.1, 1.9, 2, -1, -1.1, -1.9, -2
> >
> > Mike Nelson, or Larry Miller's solutions are correct.
> >
> > Chris Bensler
> > ~ The difference between ordinary and extraordinary is that little extra ~
> > <a href="http://empire.iwireweb.com">http://empire.iwireweb.com</a> - Empire
> for Euphoria</font></i>
> Good catch Chris,
> OK.. how about this function instead
>
> }}}
<eucode>
> function int(atom a)
>
> return a-remainder(a,1)
>
> end function
> </eucode>
{{{
>
> This should work with negative numbers that already are integers.
>
> Mark K. Akita
> <a href="http://marksarts.blogspot.com">http://marksarts.blogspot.com</a>
It's interesting that works. I would have expected the result of anything
divided by 1 to be equal to itself (1.2/1 = 1.2). Apparently remainder() does
integer division (1.2/1 = 1).
Chris Bensler
~ The difference between ordinary and extraordinary is that little extra ~
http://empire.iwireweb.com - Empire for Euphoria
|
Not Categorized, Please Help
|
|