本文介绍了振荡器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了这个用于证券分析的ob / os振荡器。唯一的

是结果总是负面的。如-96。我查看了

以及此代码,对我来说看起来很好。有没有麻烦?


#include< stdio.h>

#include< stdlib.h>


双os(双倍价格,双倍价格)

{double os;

os = price-ma / ma * 100;

返回操作系统;

}

int main(int argc,char * argv [])

{if(argc!= 3)

{fprintf(stderr," usage error \ n");

退出(EXIT_FAILURE);

}

双倍价格,马;

price = strtod(argv [1],NULL);

ma = strtod(argv [2],NULL);

printf("%f.2 \ n",os(price,ma));

返回0;

}


谢谢。

I have written this ob/os oscillator for securities analysis. The only
thing is that the result is always negative. Such as -96. I have looked over
and over this code and it looks fine to me. Is there any trouble?

#include <stdio.h>
#include <stdlib.h>

double os(double price,double ma)
{ double os;
os=price-ma/ma*100;
return os;
}
int main(int argc,char *argv[])
{ if (argc!=3)
{fprintf(stderr,"usage error\n");
exit(EXIT_FAILURE);
}
double price,ma;
price=strtod(argv[1],NULL);
ma=strtod(argv[2],NULL);
printf("%f.2\n",os(price,ma));
return 0;
}

Thanks.

推荐答案




当ma是双倍时,ma / ma总是将是1(除非ma为0

或无穷大或NaN),所以你的操作程序总是会返回

价格 - 100。


*可能*你的意思是,os =(price - ma)/ ma * 100; ??


-

任何足够先进的bug都与功能无法区分。

- Rich Kulawiec

When ma is a double, ma/ma is always going to be 1 (unless ma is 0
or infinity or NaN), so your os routine is always going to return
price - 100 .

*Possibly* you meant something like, os = (price - ma) / ma * 100; ??

--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec




啊,我明白了。非常感谢沃尔特。那一定是问题所在。尚未使用

到所有C'的括号:)


Bill

Ah I see. Thanks much Walter. That must be the problem. Not quite used
to all C''s parenthesis yet :)

Bill


这篇关于振荡器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 19:18