Re: integer() function unexpected behavior

new topic     » goto parent     » topic index » view thread      » older message » newer message

Tone Škoda wrote:
> 
> Derek Parnell wrote:
> 
> > The integer() function determines if the value supplied can be (or is) 
> > stored as an integer, and not whether or not the value has a decimal
> > compoment. 
> 
> but shouldn't 1.0 be stored as atom? i think i read that once in some
> optimization
> tips.

I understand your concern, but as I said, integer() reports if a number *CAN*
be stored as an integer. Not if it is an integer or an atom? You cannot use
integer() to determine if a literal (or any value) is actually an floating
point number or an integer.

 
> well, i'm doing another autoresizer and i wanted to use 1.0 to mean 100% and 1
> to mean
> 1 pixel. 

This is exactly where I found out about this too. That's why in win32lib you
can only specify percentage locations from 0 to 99.9999999 .

As a workaround, you could just assume that any value above 0.999999 is
trying to be 100%.


> remainder(num, 1) insead of integer() could or should be used to test if
> number has
> any fractional portion.

Not so. If you use either then literal 1.0 or 1 the remainder is still zero.

The workaround I finally accepted for win32lib is using a string ...

   createForm("Window, at=(50%, 24), size=(25%, 33%)")

The thing to remember in Euphoria is that integer and atom are just 
*storage* options for numbers. The 'atom' just means that a larger number
of numbers can be stored and thus allowing 'integer' to be optimised for
performance. This means that if you have a literal or an atom variable, 
and its current value *can* be stored as an integer, then it *is* stored
as an integer.

Thus 1 and 1.0 can both possibly be stored as an integer so therefore
Euphoria actually stores them that way. Most of the time this is a good
feature, unless you need to distinguish between the two.

-- 
Derek Parnell
Melbourne, Australia

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu