why float [again]

M

Martijn Mulder

System.Drawing.Drawing2D.Matrix comes in two flavors, int and float. When
doing graphics, you will you use float. Type double would be better, since
it is, when well applied, simply more acurate then float is. But things are
that there is no constructor for Matrix that accepts float.

But then, in the System.Math namespace, values like System.Math.PI and
function like Sin() and Cos() all return doubles. I can cast, of course, and
I do, but why?

Why float?

What is the reason there is a 'float' type in the first type, when you can
do all your floating point calculations with a double. CPU register size in
the hardware cannot be the reason since it is hardware specific.
 
S

Stoitcho Goutsev \(100\)

Hi,

I can't give you an answer why, but I guess there might be two reasons:
1. float is 32-bit vs double is 64-bit
2. Underlying GDI+ methods use 32-bit floating-point numbers.
 
M

Martijn Mulder

That is why I have problems with float. Who cares about the bit-size of
floating numbers? Tomorrow float takes 512 bits and double takes 1024. And
the underlying GDI+ methods will take advantage of that
 
W

Willy Denoyette [MVP]

| That is why I have problems with float. Who cares about the bit-size of
| floating numbers? Tomorrow float takes 512 bits and double takes 1024. And
| the underlying GDI+ methods will take advantage of that
|

What makes you think that?
Tomorrow float will still be a 32 bit and a double still be 64 bit, and GDI+
(if it still exists) will still treat them as such.


Willy.
 
M

Martijn Mulder

| That is why I have problems with float. Who cares about the bit-size of
| floating numbers? Tomorrow float takes 512 bits and double takes 1024.
And
| the underlying GDI+ methods will take advantage of that
|

What makes you think that?
Tomorrow float will still be a 32 bit and a double still be 64 bit, and
GDI+
(if it still exists) will still treat them as such.


Willy.

Why? Is it carved in stone that float is 32 bit an double 64 bit? It is just
what today's hardware can handle. Let us hope that GDI+ becomes better in
the future. Let us hope that it will be better than what it is now (it will.
I have no doubt about that). But in the foreseable future the register sizes
that we are accustumed to now wisill be laughable small
 
J

Jon Skeet [C# MVP]

Martijn Mulder said:
Why? Is it carved in stone that float is 32 bit an double 64 bit?

It's carved in the specification.
It is just what today's hardware can handle.

No, it's in the specification, which people should be able to rely on.
The world has learned the lesson from the mess of C's decision to only
impose minimum requirements on types.
Let us hope that GDI+ becomes better in
the future. Let us hope that it will be better than what it is now (it will.
I have no doubt about that). But in the foreseable future the register sizes
that we are accustumed to now wisill be laughable small

Perhaps - in which case there will be extra types to cope with those.
If C# is still around, float will still be 32 bits and double will
still be 64 bits.
 
M

Martijn Mulder

What makes you think that?
It's carved in the specification.

No, it's in the specification, which people should be able to rely on.
The world has learned the lesson from the mess of C's decision to only
impose minimum requirements on types.


Perhaps - in which case there will be extra types to cope with those.
If C# is still around, float will still be 32 bits and double will
still be 64 bits.



Thank you
 

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

Top