struct complex_float {
float real,imaginary;
};
typedef struct complex_float complex_float;
complex_float complex_add(complex_float a, complex_float b)
{
complex_float s;
s.real = a.real+b.real;
s.imaginary = a.imaginary+b.imaginary;
return s;
}
--
-- *-----------------------------* Phil Howard KA9WGN * --
-- | Inturnet, Inc. | Director of Internet Services | --
-- | Business Internet Solutions | eng at intur.net | --
-- *-----------------------------* philh at intur.net * --
I know that if I define a function with an argument type float, it is
really promoted to double.
Not if you use a function prototype.
But what about an argument that is a struct
containing a float, or more than one float? For example:
Float objects always stay floats. Float arguments without a function
prototype are promoted to double.
--
(supporter of the campaign for grumpiness where grumpiness is due in c.l.c)
Please: do not email me copies of your posts to comp.lang.c
do not ask me C questions via email; post them instead
No, that's only true if
(1) you call the function without a prototype in scope, or
(2) it's a variable argument to a variadic function like 'printf'.
So if I prototype
void foo (float bar);
and then call 'foo', the argument is not promoted to 'double'. Notice
that it would be quite incorrect to call this function without a prototype
because then the promotion would take place and the function would receive
the "wrong" argument type (receives a double when expecting a float).
>But what about an argument that is a struct
>containing a float, or more than one float? For example:
These are never converted even in the cases mentioned above.
Cheers,
Richard
--
Richard Stamp
Churchill College, Cambridge
This is one of those unfortunate design decisions in the language. A good idea
at the time, but now looks a bit ugly. Personally, I don't use float at all,
unless I really, really have to. Memory is cheap, and accuracy from a larger
type is more than worth the cost in space.
Except when it's not. Never speak in absolutes. Never say never.
rats... I just did.
--
C-FAQ ftp sites: ftp://ftp.eskimo.com ftp://rtfm.mit.edu
Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-FAQ Book: ISBN 0-201-84519-9.
Want Software? Algorithms? Pubs? http://www.infoseek.com
User923005> This is one of those unfortunate design decisions in the
User923005> language. A good idea at the time, but now looks a bit
User923005> ugly. Personally, I don't use float at all, unless I
User923005> really, really have to. Memory is cheap, and accuracy from
User923005> a larger type is more than worth the cost in space.
User923005> Except when it's not. Never speak in absolutes. Never say
User923005> never.
User923005> rats... I just did.
As far as I know, Quake2 uses floats instead of doubles. And I guess it's for
speed reasons...
--
Nils Goesche
My obscure opinions are my very own.