简体   繁体   English

在这种情况下,“ =”运算符是做什么的? sqrtf(1-(t = t / d-1)* t);

[英]What does the '=' operator do in this context? sqrtf(1 - (t = t / d - 1) * t);

The following code is part of an easing equation. 以下代码是缓动方程的一部分。 I'm just interested in the syntax. 我只是对语法感兴趣。

sqrtf(1 - (t = t / d - 1) * t);

I haven't seen the '=' operator used like this before. 我以前从未见过像这样使用'='运算符。 What does it do in this context? 在这种情况下,它做什么?

Edit: the code is from a well-known Robert Penner easing function, written in ActionScript: 编辑:该代码来自用ActionScript编写的著名的Robert Penner缓动函数:

static function easeOut (t:Number, b:Number, c:Number, d:Number):Number {
    return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
}

The = operator here does what it always does. 这里的=运算符将执行其始终执行的操作。 In this case it modifies t (setting it to t / d - 1 ). 在这种情况下,它将修改t (将其设置为t / d - 1 )。 The value returned from that part of the equation will be the new value of t . 从等式的该部分返回的值将是t的新值。

This becomes confusing because t is used later in the equation, and I wouldn't be sure that every compiler would treat it the same. 这变得令人困惑,因为在等式的后面使用了t ,而且我不确定每个编译器都将t视为相同。 ie is the third t going to use the old value or the new value? 第三个t将使用旧值还是新值?

I would avoid writing equations in this way. 我将避免以这种方式编写方程式。 It's lazy and I don't see any good reason to do it. 这很懒,我看不出有什么充分的理由这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM