REBOL 3.0

Pairs as Floating Point?

Carl Sassenrath, CTO
REBOL Technologies
15-Jul-2010 19:00 GMT

Article #0326
Main page || Index || Prior Article [0325] || Next Article [0327] || 10 Comments || Send feedback

Graphical points and sizes use a datatype called PAIR! which holds an X/Y pair of integers. However, our graphics system supports sub-pixels, and we need to ask if it makes sense to allow PAIR to be based on floating point values?

Of course, such a change creates a few deeper issues than just graphics point or size specification. For example, math operations no-longer auto-truncate to integer values. Today:

>> 5x5 / 2
== 2x2

but, that would become:

>> 5x5 / 2
== 2.5x2.5

In many cases, that's not a problem and may in fact be desirable, but in cases where real pixels are required, ambiguity arises. For example, what happens here:

>> make image! 5x5 / 2

Do fractional sizes round up or down?

And, the example above is a simplification. Floating point is a non-precise mathematical system -- that is, numbers are approximate and may be slightly larger or smaller than a desired value. This impacts operations like comparisons between values, including the meaning of "equal to zero".

Of course, most of these issues can be solved with the various "strictness" comparison operators. In addition, the use of ROUND will become important for many algorithms.

Finally, none of this is done deal yet. Over the next few days, we will build an experimental version of R3 that contains the basic change of pair! to floating point. We can then weigh the advantages of the change with the disruption it causes to our code.

10 Comments

REBOL 3.0
Updated 28-Apr-2024 - Edit - Copyright REBOL Technologies - REBOL.net