Author Topic: For loop doesen't go over 2048?  (Read 1198 times)

Code: [Select]
function Calculate()
{
for(%i=0;%i<100000000;%i+=0.0001)
{
%a=1/%i;
%b=2/%i;
%c=3/%i;

echo(%i);

if(%a="0.106" && %b="0.0346" && %c="0.0146")
{
echo("FINISHED" SPC %i);
}
}
}

I'm trying to use this code to see what number; if it exists, can come out with 0.106, 0.0346 and 0.0146 when dividing the 1, 2 or 3

but it stops at 2048, which is not the number I am looking for

What are you trying to do
It makes no sense
Or does it?

comment: no idea why you need this.


solution: use a while() loop.

test: also, try setting your max value to one zero less. torque has a problem with big strings.

Btw

2/x = 0.0346
2 = 0.0346*x
2/0.0346 = x

Is it that hard

Why are you using = to compare two numbers, use ==

Why are you using = to compare two numbers, use ==
He's using quotes as well

Anyway, you can just use regular math to find the exact answer for this, as opposed to trying every number in existence...

He's using quotes as well

Anyway, you can just use regular math to find the exact answer for this, as opposed to trying every number in existence...
I don't know how I would do it for all 3 at the same time

the math for each is completely different from eachother

I need to know what single number, will obtain these results from 1, 2 and 3

1.06 = 1 / X
X = 0.943396226415094339622641509 43396
0.0346 = 2 / X
X = 57.80346820809248554913294797 6879

i don't think there's a number that works

^ Woa that was really difficult phlack thanks a bunch

Well I need a calculation that works so I don't have stretchy brick textures in my generator

Code: [Select]
int main(int argc, char* argv[])
{
        float i = 0;
        float iu3, iu2, iu1;
        while(1)
        {
                i += 0.00001;
                iu1 = 1/i;
                iu2 = 2/i;
                iu3 = 3/i;
                if(iu1==0.106 && iu2 == 0.0346 && iu3==0.0146)
                {
                        printf("FOUND!!!! %f\n", i);
                        return 1;
                }
        }
}

im nice so i'll run it in c++ on my server for you

edit: calculation ran, no such number. like phflack said.
« Last Edit: August 07, 2012, 08:33:37 PM by TripNick »

Why do we need a program to see that this is not possible, or try and calculate the values of X?

It should be clear straight away that 1 / i will never be larger than 2 / i.

The TorqueScript interpreter has no "loop stopper" that automatically kicks in if you reach 20480000 iterations. for and while loops go on forever until reaching the condition, encountering break or encountering return.
« Last Edit: August 09, 2012, 04:01:54 AM by Port »

Code: [Select]
function Calculate()
{
for(%i=0;%i<100000000;%i+=0.0001)
{
%a=1/%i;
%b=2/%i;
%c=3/%i;

echo(%i);

if(%a="0.106" && %b="0.0346" && %c="0.0146")
{
echo("FINISHED" SPC %i);
}
}
}

I'm trying to use this code to see what number; if it exists, can come out with 0.106, 0.0346 and 0.0146 when dividing the 1, 2 or 3

but it stops at 2048, which is not the number I am looking for
Let me fix that for you. Line by line.
Code: (Line 3) [Select]
for(%i=0;%i<100000000;%i+=0.0001)You're using numbers way too extreme.
Try %i<100000
Code: (New Line 3) [Select]
for(%i=0;%i<100000;%i+=0.0001)
Code: (Line 11) [Select]
if(%a="0.106" && %b="0.0346" && %c="0.0146")Another issue. You're not checking if %a %b and %c equal those values. You're SETTING them.
= is set, meaning you're changing the value of the variable.
== is equal value
$= is equal string
Code: (New Line 11) [Select]
if(%a == 0.106 && %b == 0.0346 && %c == 0.0146 )
That is all. Thank you.

Please watch for things like this in the future.


If none of this fixes the actual problem, then look towards other posts.
I'm just pointing out these two mistakes.

Well I need a calculation that works so I don't have stretchy brick textures in my generator

Do it differently. This is not the correct way.