Re: Floating point arithmetic model of C...
- From: nick_keighley_nospam@xxxxxxxxxxx
- Date: Tue, 17 Mar 2009 02:30:40 -0700 (PDT)
On 16 Mar, 18:20, "almu...@xxxxxxxxxxxxx" <almu...@xxxxxxxxxxxxx>
wrote:
<snip>
I have reverse engineered some 99-C
code into C# and have noticed an unusual bug(it causes the C# to not
work properly).
define "not work properly". How do you know the original C code "works
properly"? How did you detect the "unusual bug"?
I habve traced it down to a single method and have
compared results with the C version and noticed that small differences
in the results build up (as the calulation i s inside a loop with a +=
operator working on it).
If it's a small piece of code could you post the C code here?
And tell us what result you expect it to produce.
And:-
POST THE C# TO A C# NEWSGROUP!!
Obviously the first thing I checked was the syntax.
I'd have expected your compiler to do that
No error there.
Next on the list was the classic roundoff error.
I must have been asleep in the lecture in my Numerical Analysis course
that dealt with the subject of "classic roundoff error". What *is*
CRE?
I'm using double so I
[thought] that mine would be better.
The C code uses float and the C# uses double? And you
expect to get the same result?
It is better (ie more accuratte) but
does not produced the right results.
it is more accurate, but wrong? Sorry, what does accurate but wrong
mean?
As mentioned before the small
difference that seems to creep in mount up. Next was to use
System.Single
no idea what System.Single is
which resulted in some small improvement. So i was then
in the domain of "the floating point model in C is different *somehow*
from that of the C# model"
I'm not convinced you've demonstrated this. You could have a mistake
in the
C# or in the original C. Or you could have some numerically unstable
computation that is just magnifying small differences in the
environment.
So I implement a C++ DLL of the offending method (as C++ is closer
to C than C# or so I have been told as regards floating point model) .
Worked a bit better but error still replicating.
"worked better", how do you know its better? How do you know the
errors
are replicating?
Anyone with any ideas? I will post some code and the inputs and output
to show you what i mena in my next post. This is doing my head in....
Have you asked on a C# newsgroup?
--
Nick Keighley
GOD is REAL unless a type declaration to the contrary is made
.
- References:
- Re: Floating point arithmetic model of C...
- From: jameskuyper
- Re: Floating point arithmetic model of C...
- Prev by Date: Re: Segmentation fault
- Next by Date: Re: "Portable" C compilers?
- Previous by thread: Re: Floating point arithmetic model of C...
- Next by thread: Re: Floating point arithmetic model of C...
- Index(es):
Relevant Pages
|