将学术数学符号转换为 C 代码
即使对数学有一定了解的人也可能会笑,但我不记得数学中有多少符号规则,我需要帮助将其转换为 C 代码。非常感谢您的帮助:
214
10,000 {(10,000 × [1+.0599/365] )} +300
answer = ────────────────────────────────────────────
214
.1+(1+(i/365))
Those of you that are even moderately knowledgable of math will likely laugh, but I don't remember what much of the notation rules in math and I need assistance converting this into C code. Your help is greatly appreciated:
214
10,000 {(10,000 × [1+.0599/365] )} +300
answer = ────────────────────────────────────────────
214
.1+(1+(i/365))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否正在寻找一个程序来为您翻译该内容,或者只是一次性转换?
如果这只是一次性的转换,那就没有那么令人兴奋了。
假设我正确地阅读了你的语法:
不过,我会说,你可能在将指数提高到那么高的指数和除法时遇到问题。更有可能的是,您必须转换为日志并在日志空间中进行数学计算,然后再进行转换。
看起来像什么:
使用日志可以防止您遇到下溢,而这些类型的计算很可能会遇到下溢。
Are you looking for a program to translate that for you, or just a one-off conversion?
If it's just a one off conversion, it's not that exciting.
Assuming I've read your syntax correctly:
I will say, though, that you may have an issue with raising things to that high of an exponent and dividing. More likely you will have to translate to logs and do your math in the log space, and convert afterwards.
What that might look like:
The use of log may prevent you from hitting underflow, which you may very well hit with these types of computations.
很简单 - 只需要注意几个常见错误。
在常数后面加上 .0(特别是在分母中),以便“c”将计算视为浮点数学而不是整数。
在“C”中,100/1000 是 0 100/1000.0 是 0.1
随意使用括号 - 不要相信记住优先级规则。
您需要在任何地方使用 * 来表示乘法 3(1+2) 不是乘法。
pow(x,y) 函数用于 x^y。现代 C++ 编译器具有优化版本,其中 y 是整数,因此 x^2 比 x^2.0 快得多
Simple - just a couple of common mistakes to watch for.
Put a .0 after the constant numbers (especially in the denominator) so that 'c' treats the calculation as floating point math rather than integer.
In 'C' 100/1000 is 0 100/1000.0 is 0.1
Use brackets liberally- don't trust remembering the precedence rules.
You need to use * everywhere for multiplication 3(1+2) is not a multiplication.
The pow(x,y) function is used for x^y. Modern C++ compilers have optimized versions where y is an integer, so x^2 is much faster than x^2.0
您是否正在寻找
pow(x,y)
函数来计算幂?Are you looking for the
pow(x,y)
function to calculate the power ?我想我是对的。 :)
I think I got that right. :)