Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables 仅使用算术运算符复制变量_Variables_Math_Integer Arithmetic_Paradox Scripting - Fatal编程技术网

Variables 仅使用算术运算符复制变量

Variables 仅使用算术运算符复制变量,variables,math,integer-arithmetic,paradox-scripting,Variables,Math,Integer Arithmetic,Paradox Scripting,在没有直接赋值函数的情况下,将一个变量的值复制到另一个变量的最佳方法是什么 变量是2字节的固定点号,最大值为2147483.647。可用的运算符有(为清晰起见,重新格式化): add(,)将常量值添加到给定变量 减法(,)哪个减法 乘法(,)哪个乘法 划分(,)哪个划分 检查(,),它使用运算符op将variable1的值与的值进行比较,并返回布尔值操作可以是=, 设置(,)它设置变量的值 脚本语言有基本的控制流,它有while和if(但不是else)以及基本的布尔运算符和,或,非和非 我们

在没有直接赋值函数的情况下,将一个变量的值复制到另一个变量的最佳方法是什么

变量是2字节的固定点号,最大值为2147483.647。可用的运算符有(为清晰起见,重新格式化):

  • add(,)
    将常量值添加到给定变量
  • 减法(,)
    哪个减法
  • 乘法(,)
    哪个乘法
  • 划分(,)
    哪个划分
  • 检查(,)
    ,它使用运算符
    op
    variable1
    的值与
    的值进行比较,并返回布尔值<代码>操作可以是
    =
  • 设置(,)
    它设置变量的值
  • 脚本语言有基本的控制流,它有
    while
    if
    (但不是
    else
    )以及基本的布尔运算符
我们的第一次尝试只是:

while = {
    count = var1 //loop var1 times
    change_variable = { which = var2 value = 1 } //increment by one
}
我的下一次尝试是:

set_variable = { which = new value = 1 }
while = {
    limit = { NOT = { check_variable = { which = old value = new} } }
    if = {
        limit = { 
            check_variable = { which = old value > new } 
            check_variable = { which = stage value = 0 }
        }
        multiply_variable = { which = new value = 10 }
    }
    if = {
        limit = { 
            check_variable = { which = stage value = 0 } 
            check_variable = { which = old value < new } 
        }
        set_variable = { which = stage value = 1 }
    }
    if = {
        limit = {
            check_variable = { which = stage value = 1 }
            check_variable = { which = old value < new }
        }
        subtract_variable = { which = new value = 1 }
    }
}
set_变量={which=新值=1}
而={
limit={NOT={check_variable={which=old value=new}}
如果={
极限={
检查_变量={其中=旧值>新值}
检查_变量={which=stage value=0}
}
乘法_变量={其中=新值=10}
}
如果={
极限={
检查_变量={which=stage value=0}
检查_变量={which=旧值<新值}
}
set_变量={which=stage value=1}
}
如果={
限制={
检查_变量={which=stage value=1}
检查_变量={which=旧值<新值}
}
减法_变量={which=新值=1}
}
}
例如,从1开始,乘以10直到大于目标,然后减去1直到达到目标

但我相信有更好的方法

上下文: 最近在游戏“Stellaris”中使用的脚本语言补丁破坏了变量赋值函数<上面的代码>集合
应该是
集合(,
)。这已经破坏了很多现有代码,不知道它会被破坏多久。

因为2147483.647是a(2-1的幂)/1000,我可以使用2的连续幂一次逼近1位的解:(用C编写,仅使用等效操作)

result=0;
结果+=1073741.824;
if(var
只需要32次比较(如果精度较低或知道上限,则需要较少比较)。

因为2147483.647是a(2-1的幂)/1000,我可以使用2的连续幂一次逼近解1位:(使用C编写,仅使用等效操作)

result=0;
结果+=1073741.824;
if(varresult = 0;
result +=  1073741.824;
if( var < result )
    result -=  1073741.824;

result += 536870.912;
if( var < result)
    result -= 536870.912;

result += 268435.456;
if( var < result)
    result -= 268435.456;

result += 134217.728;
if( var < result)
    result -= 134217.728;

result += 67108.864;
if( var < result)
    result -= 67108.864;

result += 33554.432;
if( var < result)
    result -= 33554.432;

result += 16777.216;
if( var < result)
    result -= 16777.216;

result += 8388.608;
if( var < result)
    result -= 8388.608;

result += 4194.304;
if( var < result)
    result -= 4194.304;

result += 2097.152;
if( var < result)
    result -= 2097.152;

result += 1048.576;
if( var < result)
    result -= 1048.576;

result += 524.288;
if( var < result)
    result -= 524.288;

result += 262.144;
if( var < result)
    result -= 262.144;

result += 131.072;
if( var < result)
    result -= 131.072;

result += 65.536;
if( var < result)
    result -= 65.536;

result += 32.768;
if( var < result)
    result -= 32.768;

result += 16.384;
if( var < result)
    result -= 16.384;

result +=  8.192;
if( var < result)
    result -=  8.192;

result +=  4.096;
if( var < result)
    result -=  4.096;

result += 2.048;
if( var < result)
    result -= 2.048;

result += 1.024;
if( var < result)
    result -= 1.024;

result += 0.512;
if( var < result)
    result -= 0.512;

result += 0.256;
if( var < result)
    result -= 0.256;

result += 0.128;
if( var < result)
    result -= 0.128

result += 0.064;
if( var < result)
    result -= 0.064;

result += 0.032;
if( var < result)
    result -= 0.032;

result += 0.016;
if( var < result)
    result -= 0.016;

result += 0.008;
if( var < result)
    result -= 0.008;

result += 0.004;
if( var < result)
    result -= 0.004;

result += 0.002;
if( var < result)
    result -= 0.002;

result += 0.001;
if( var < result)
    result -= 0.001;