Some sort of weird round off error -- please help!

K

Kenny McCormack

I don't think I ever heard so much nonsense from one man.

So, 4.0 is an approximation of 4 is it?

Yes. A very good one, in fact.

I doubt you'll be able to dig up anything in the definition of
"approximation" that precludes the error value being 0.
 
R

Richard Bos

I just though that the C forum would be a better place to get help
first, not sure why. I have implemeneted a C# version using doubles so
my results are probably more accurate than the authors (its legacy
code I'm translation).
Problem is though - it does not give the exact same results.

Here's another question for you to ponder about*: why on earth do you
care about getting the _exact_ same results, when you're using floating
point variables (and float rather than double, at that) anyway? Don't
you know what every computer scientist should know about floating-point
arithmetic?

Richard

* and I mean that - reason this out for yourself
 
R

Richard Bos

Han from China said:
Nit: Three *real* floating types.

6.2.5{11}: "The real floating and complex types are collectively
called the floating types."

Not in pre-99 C, which is what the OP is using.

Richard
 
R

Richard Bos

Keith Thompson said:
Yes, that's a nice generalization.

Not even that. _Most_ floating point values are approximations, but I
challenge you to find a C implementation on which, e.g., 0.0 is not
represented exactly.

Richard
 
M

Mark Wooding

Not in pre-99 C, which is what the OP is using.

You're right. But, truth be told, I got lucky, and I'm grateful for
Han's correction which reminded me that C now has complex numbers.

Thank you also to Richard, because otherwise I'd have missed the
correction.

-- [mdw]
 
D

Dik T. Winter

> Here's another question for you to ponder about*: why on earth do you
> care about getting the _exact_ same results, when you're using floating
> point variables (and float rather than double, at that) anyway? Don't
> you know what every computer scientist should know about floating-point
> arithmetic?

Yes, that is a big problem. I know of somebody who would not allow
vectorising optimisation because the results would not be exactly the
same. It is not something only computer scientists should now about, but
also numerical mathematicians.
 
D

Dik T. Winter

> Not even that. _Most_ floating point values are approximations, but I
> challenge you to find a C implementation on which, e.g., 0.0 is not
> represented exactly.

Hrm. ICL went out of business before C was implemented on them, otherwise
that would have been a prime example.
 
A

almurph

What happens if FLT_EVAL_METHOD is 2?

I ignored that possiblity because the OP said "pre-C99" (though he
might be using a C99 compiler anyway), and because I've never looked
at that stuff in detail.

If I understand correctly, it would be evaluated as a long double
(which may of course be the same as double, though I don't see why an
implementation would set it to 2 in that case).

In any case it would be ocnverted to a double for the printf(), so
the inconsistent values he sees must be float and double versions.

-- Richard[/QUOTE]

Hi everyone,

Thansk for all the info. i've found the C# type called:
System.Single to be very useful. I'm getting more accurate, consistent
results now. not perfect but a lot better. Thansk for all the info,
its been an education.

Merci,
Al.
 
A

almurph

Thanks everyone for all the info. I've discovered the C# type
System.Single which appears to be a bit more stable. Its not perfect
but it is better.
Thanks for all your comments, its been an education.

Merci
Al.

What happens if FLT_EVAL_METHOD is 2?

I ignored that possiblity because the OP said "pre-C99" (though he
might be using a C99 compiler anyway), and because I've never looked
at that stuff in detail.

If I understand correctly, it would be evaluated as a long double
(which may of course be the same as double, though I don't see why an
implementation would set it to 2 in that case).

In any case it would be ocnverted to a double for the printf(), so
the inconsistent values he sees must be float and double versions.

-- Richard[/QUOTE]
 
R

Richard Bos

Dik T. Winter said:
Hrm. ICL went out of business before C was implemented on them, otherwise
that would have been a prime example.

It would've been a prime example of something which isn't a C
implementation.

Richard
 
D

Dik T. Winter

>
> It would've been a prime example of something which isn't a C
> implementation.

You are right. Lucky for them they went out of business. it would have been
impossible to provide a conforming C implementation on it.
 
R

Richard Bos

Dik T. Winter said:
You are right. Lucky for them they went out of business. it would have been
impossible to provide a conforming C implementation on it.

Mind you, I suspect that, should push have come to shove, it would
merely have proved decidedly awkward, hacky, and possibly inefficient,
not actually impossible.

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top