在对值进行平方后,是否有一种简单的方法来保留符号.我目前有:
float signed_square(float x) {
if (x > 0) {
return x * x;
} else {
return -(x * x);
}
}
Run Code Online (Sandbox Code Playgroud)
dru*_*nly 11
正如我在评论中所说:
float signed_square(float x){
return x * fabs(x);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1174 次 |
| 最近记录: |