in reply to Re^5: Infinity and Inf? (MAX_INT)
in thread Infinity and Inf?

IMHO it doesn't make sense to restrict the rangeoperator to signed integers when floats can still represent bigger integers

I can sort of sympathise with that.

But for counterpoint, does it make sense to restrict the iteration of a float iterator to unitary integer increments?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^7: Infinity and Inf? (MAX_INT)
by LanX (Saint) on Sep 01, 2010 at 17:12 UTC
    I don't know if I understand you right, you mean to allow rational stepwidth?

    Something like BASIC's FOR 3.3 TO 7.8 STEP 0.5?

    IMHO the C-Style for is already meant to handle this.

    Cheers Rolf

      Nit: C-Style for doesn't handle that very well. STEP 0.5 is ok since it's a sum of powers of 2 (2-1), but let's take STEP 0.1 instead:

      $ perl -E'for (my $_=0; $_<=7; $_+=0.1) { say }' ... 5.6 5.7 5.8 5.9 5.99999999999999 6.09999999999999 6.19999999999999 6.29999999999999 6.39999999999999 6.49999999999999 6.59999999999999 6.69999999999999 6.79999999999999 6.89999999999999 6.99999999999999

      Generate the floats from integers to avoid compounding errors:

      $ perl -E'for (0..70) { say $_/10 }' ... 5.6 5.7 5.8 5.9 6 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7
      the C-Style for is already meant to handle this.

      Indeed. Which is (probably) why the range operator only handles integers.