从C#定义转换为C# [英] #define conversion from C to C#
本文介绍了从C#定义转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是C代码:
/* LERP(a,b,c) = linear interpolation macro, is 'a' when c == 0.0 and 'b' when c == 1.0 */
#define LERP(a,b,c) (((b) - (a)) * (c) + (a))
的 http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_T.html
等于这个C#代码?
private static double LERP(double a, double b, double c) { return (((b) - (a)) * (c) + (a)); }
?
推荐答案
没有。
考虑以下几点:
no. consider the following:
线性插值(X +,1,2);
C代码也可能增加两次x [由@phresnel提到它是未定义],而C#代码是完全定义的副作用,而且会增加X只一次。
The c code might also have a side effect of increasing x twice [it is undefined as mentioned by @phresnel], while the c# code is perfectly defined, and will increase x only once.
的结果也可能不同,因为第一 A
和第二个[在宏]可能具有一个不同的值,因为它可能会在第一个增加
the result also might be different, since the first a
and the second one [in the macro] might have a different value, since it might have increased in the first one.
这篇关于从C#定义转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文