标题:[求助]请会VC的老大,帮帮忙!
只看楼主
kekewf
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-6-19
 问题点数:0 回复次数:1 
[求助]请会VC的老大,帮帮忙!

我想把以前C编的程序,转换成VB的,可我转了以后老是提示我 overflow! 我实在搞不懂了!
请各位大虾给看看,这是为什么?
VC程序

#include <stdio.h>
#include <stdlib.h>
#include <math.h>#define SRATE 32000l
#define NTODO 3
#define M_PI 3.14159265358979323846
float fcoefs[NTODO];
float fstate1[NTODO];
float fstate2[NTODO];
short findex = 0;
float Freqs[NTODO] = {100.00,125.00,280.00};
FILE *outfile;
#define INIT_TWO_COS(arg) fcoefs[findex++] = (float)2.0 * (float)cos(((float)2.0)*((float)M_PI)*((float)arg)/(float)SRATE)

main()
{ short intsum;
unsigned long samplenum;
for(findex = 0; findex < NTODO; findex++)
fcoefs[findex] = (float)2.0 * (float)cos(((float)2.0)*((float)M_PI)*Freqs[findex]/(float)SRATE);
for (findex = 0; findex < NTODO; findex++) {
fstate2[findex] = (float)1.0;
fstate1[findex] = ((float)0.5) * fcoefs[findex];
}

outfile = fopen("ee.bin","wb");

for (findex = 0; findex < NTODO; findex++)
{ int j, rval;
float sum, tempf;
rval = rand();
for (j = 0; j < rval; j++) {
sum += tempf = fcoefs[findex] * fstate1[findex] - fstate2[findex];
fstate2[findex] = fstate1[findex];
fstate1[findex] = tempf;
}

}

for (samplenum = 0; samplenum < 3200l; samplenum++) {
register float tempf;
register float sum;
sum = (float)0.0;
for (findex = 0; findex < NTODO; findex++) {
tempf = fcoefs[findex] * fstate1[findex] - fstate2[findex];
sum += ((float)512.0)*tempf;
fstate2[findex] = fstate1[findex];
fstate1[findex] = tempf;
}
sum = sum * (float)(100.0/((float)NTODO));
intsum = (short)sum;
fwrite(&intsum,2,1,outfile);
printf("%d,\n",intsum);
}
fclose(outfile);
}

VB程序:

Dim Freqs(0 To 6) As Double
Dim NTODO As Integer
Dim Findex As Integer
Dim intsum As Integer
Dim Samplenum As Long
Dim Pi As Double
Dim Srate As Integer
Dim fcoefs(0 To 3) As Double
Dim Fstate1(0 To 3) As Double
Dim Fstate2(0 To 3) As Double
Dim Normal(0 To 6) As Double
Dim j As Integer, rval As Long
Dim Sum As Single, tempf As Double
Dim FileNameS As String
Pi = 3.14159265358979
Srate = 32000
NTODO = 3

Freqs(0) = 100
Freqs(1) = 125
Freqs(2) = 280
Freqs(3) = 0

Randomize
For Findex = 0 To NTODO
fcoefs(Findex) = 2 * Cos(2 * Pi * Freqs(Findex) / Srate)
Next Findex
For Findex = 0 To NTODO
Fstate2(Findex) = 1#
Fstate1(Findex) = 0.5 * fcoefs(Findex)
Next Findex
For Findex = 0 To NTODO
rval = Int(50 * Rnd)
For j = 0 To rval
tempf = fcoefs(Findex) * Fstate1(Findex) - Fstate2(Findex)
Sum = Sum + tempf
Fstate2(Findex) = Fstate1(Findex)
Fstate1(Findex) = tempf
Next j
Next Findex
Open ("C:\ee.bin") For Binary As #2
For Samplenum = 0 To 3199
Sum = 0
For Findex = 0 To NTODO
tempf = fcoefs(Findex) * Fstate1(Findex) - Fstate2(Findex)
Sum = Sum + (512# * tempf)
Fstate2(Findex) = Fstate1(Findex)
Fstate1(Findex) = tempf
Next Findex
Sum = Int(Sum * (100 / NTODO))
intsum = Sum
Put #2, , intsum
Next Samplenum
Close #2

[此贴子已经被作者于2006-6-19 18:26:08编辑过]

搜索更多相关主题的帖子: 老大 float define include 
2006-06-19 18:15
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
得分:0 
不懂VC,,看不懂...!!!

我的msn: myfend@
2006-06-19 18:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-73423-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022594 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved