[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Numeric for loop with rationals
- From: Paige DePol <lual@...>
- Date: Tue, 30 Jan 2018 12:15:00 -0600
Egor Skriptunoff <egor.skriptunoff@gmail.com> wrote:
> > for j = "1", 2, 3 do print(j, math.type(j)) end
> 1.0 float
> > for j = 1, "2", 3 do print(j, math.type(j)) end
> 1 integer
> > for j = 1, 2, "3" do print(j, math.type(j)) end
> 1.0 float
>
> Why does the loop variable hold not an integer sometimes?
This discrepancy happens in the OP_FORPREP instruction:
if (ttisinteger(init) && ttisinteger(pstep) &&
forlimit(plimit, &ilimit, ivalue(pstep), &stopnow)) {
If the initial value and the step value are integers then
it calls forlimit() which will covert "2" into an integer
value as well, and you will get an integer for loop.
However, if either init or pstep are not integer values then
the if/else drops down the the next block which attempts to
convert all loop parameters into floating point values.
~Paige
- References:
- Re: Numeric for loop with rationals, Soni "They/Them" L.
- Re: Numeric for loop with rationals, dyngeccetor8
- Re: Numeric for loop with rationals, Soni "They/Them" L.
- Re: Numeric for loop with rationals, Francisco Olarte
- Re: Numeric for loop with rationals, Soni "They/Them" L.
- Re: Numeric for loop with rationals, Dirk Laurie
- Re: Numeric for loop with rationals, Soni "They/Them" L.
- Re: Numeric for loop with rationals, Dirk Laurie
- Re: Numeric for loop with rationals, Soni "They/Them" L.
- Re: Numeric for loop with rationals, Charles Heywood
- Re: Numeric for loop with rationals, Sean Conner
- Re: Numeric for loop with rationals, Egor Skriptunoff