floats/shorts vs double/longs 
Author Message
 floats/shorts vs double/longs

I'm curious to know if there's a general sentiment regarding the use of
floats vs. doubles. I normally use doubles out of habit even though there no
need to. Same goes for longs. Most of the data I use ranges in -32k to +32k
or 0-65k and there's really no need to unsigned longs. I guess the reason
I've stuck with the larger data types is thinking that doubles/longs are
more "32-bit correct" (which is crap) and since it really doesn't matter
what do most people use by habit. In addition, to the space savings and some
speed decrease, will there be any advantage to moving code to floats/shorts
in the 32-bit environment or even in a 64-bit environment?

And keep the flaming to a minimum. I don't have the time or patience.

Thanks,
Jeff.

--
Jeff D. Hamann
2601 NE Jack London Street #27
Corvallis, Oregon 97330 USA
541-740-5988

http://www.*-*-*.com/ ~hamannj



Thu, 27 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
From habit, I usually use int instead of long unless I know I am going to
need the larger range.

From habit, and for good reason, I usually use double instead of float.

Once upon a time (and I think it is still true, but I am sure someone will
correct me if I am wrong), the math library converted all floats to doubles
for internal calculation and back to float again at the end. Using doubles
avoids the conversion and presumably makes things faster.

Regards,
Sam



Thu, 27 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
A gentleman named Neil Bennett sent me the following reply. Since it didn't
show up here yet, I thought I would post it. I knew someone would know more
about this than I did. (Indeed, I once had a math co-processor before they
built them in. Now, most of the Intel processors have them -- though as I
recall, there was a cut-rate Pentium version at one time that did not.)

Hi Sam,  On the Wintel platform, the time it takes for either float (32 bits
long) or double (64 bits long) is just the same. Both are internally (in
what was called the 8087 chip - now part of the CPU) expanded to an internal
80 bit format - the operation done - and then the result converted back to
either 32 or 64 bits.
The only difference is the amount of memory taken by the different floating
point formats.
Much the same can be said about integers, too.



Thu, 27 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
On Sun, 9 Jan 2000 23:20:42 -0800, "Jeff D. Hamann"

Quote:
> guru on call:

> Software that works most of the time is a lot worse than software
> > that fails all the time.  Think about it.

> and win32 would be....

> you are so knowledgable I should email all of the simple questions regarding
> style directly to you in the future. think about it.

> and stating the blantantly obvious as a matter of answering a question
> regarding sentiment. really. dude, when you learn how to get past the
> snap-on tie, you'll understand. as your freshman computer science teacher
> probably put, "fill in all the blanks, starting with your name". small
> questions, come from small minds. try looking at the bigger picture, then
> and realize that you're not answering the question at all.





> > > I'm curious to know if there's a general sentiment regarding the use of
> > > floats vs. doubles. I normally use doubles out of habit even though
> there
> > no
> > > need to.
> > If you know there is no need to use them, then it is stupid to use them.
> > Quite likely, there is a reason but you do not know it.

> > > Same goes for longs. Most of the data I use ranges in -32k to +32k
> > > or 0-65k and there's really no need to unsigned longs.
> > Words like "most" are frightening here.  Either they are always within
> > SHORT_MIN / SHORT_MAX or they are not.  One exception can mean
> catastrophic
> > failure.  Software that works most of the time is a lot worse than
> software
> > that fails all the time.  Think about it.

> > > I guess the reason
> > > I've stuck with the larger data types is thinking that doubles/longs are
> > > more "32-bit correct" (which is crap) and since it really doesn't matter
> > > what do most people use by habit.
> > Unless correct results are involved.  If you need the larger size then you
> > do.  If you do not need more precision then you don't.  If you don't know
> if
> > you do or not, then find someone who does know and do what they tell you
> to
> > do.

> > > In addition, to the space savings and some
> > > speed decrease, will there be any advantage to moving code to
> > floats/shorts
> > > in the 32-bit environment or even in a 64-bit environment?
> > The very existance of this question is rather interesting.  Since you do
> not
> > mention what you are trying to do, anyone who answers the question is a
> > blithering idiot.  You can safely killfile them.

> > > And keep the flaming to a minimum. I don't have the time or patience.
> > Posting on USENET without time nor patience?  You had better grow some,
> you
> > whimpering simp.

Obviously you don't know who you are messing with.  Exactly what does
the term "sentiment" have to do with computer programming, in C or any
other language, or any other exacting profession?

A competent, professional programmer doesn't do anything "out of
habit", although talentless second raters might.  I don't pick
variable types out of habit, I always pick the one I want to fit the
task at hand.

If you know anything at all about C and this newsgroup, you would know
that the part of your question concerning speed increases/decreases is
both a) entirely implementation specific and b) entirely off-topic
here anyway.

However if you ever have any questions about programming in C that do
not involve either "sentiment" or "out of habit", feel free to drop in
again.

Jack Klein
--
Home: http://jackklein.home.att.net



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs


Quote:


> > I'm curious to know if there's a general sentiment regarding the use of
> > floats vs. doubles. I normally use doubles out of habit even though
there
> no
> > need to. Same goes for longs.
> You are asking us to pick your data type for you.  That is an absurd
> request, really.  The correct data type to use is the one that meets all
> project requirements and will produce robust results for all imagineable
> inputs.

No, the correct data type for Jeff is array [32] of unsigned char. With
enough of those (each with a massive 128 (or more!) bits) at your disposal,
there ain't anything worth representing that you can't represent.

  How can we know which one to choose from a generic statement like

Quote:
> the above?  Simply stated, it is impossible.

I don't see why you're being so obtuse. Jeff's a reasonable guy. It's
pretty obvious he's after the answer unsigned char [32]. Why not just
provide the correct answer and be done with it?

Quote:

> > And keep the flaming to a minimum. I don't have the time or patience.

Yes, leave the guy alone. He's a busy guy, Dann. Not like you. So put your
poleaxe away and drop this antagonism.

Quote:
> Translation, "Please flame me at the first possible opportunity."  That
type
> of phrase is the surest imaginable flame magnet.

Not at all. All he said was something like "I don't have the time,
patience, or civility to read all the carefully considered responses that
other people have had the courtesy to provide for me, because I'm an
ignorant dipstick who doesn't know any better". How is that a flame magnet?

Quote:

> BTW, killfile User923005 and your noise level will drop dramatically.

User923005 is one of the most courteous and helpful posters on the whole of
Usenet. Get off his case. I happen to know he's considering legal action
against you for defamation of character.

--
Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.

"Using an undefined-behavior-induced crash as a program's intended
error-checking mechanism strikes me as a spectacularly misguided strategy"
- Steve Summit, 7 Jan 2000.

;-)   (Will Dann spot the smiley, all the way down here?)



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs


Quote:

> No, the correct data type for Jeff is array [32] of unsigned char.
With
> enough of those (each with a massive 128 (or more!) bits)

....

Usually more than 255 bits, I think.  But don't bother to post
a reply if I'm wrong, since I don't actually have the time or
patience to read this newsgroup.

--
MJSR

Sent via Deja.com http://www.deja.com/
Before you buy.



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs

Quote:



> [snip]
> > > BTW, killfile User923005 and your noise level will drop dramatically.

> > User923005 is one of the most courteous and helpful posters on the whole
> of
> > Usenet. Get off his case. I happen to know he's considering legal action
> > against you for defamation of character.

> You don't know this guy like I do.  I happen to know him personally.  He
> sits in his bathrobe, quaffing a "Sam Adams" and gets this funny{*filter*}-eyed
> look that can only be described as deranged.  Some "Sports Center"
> announcement will come along saying something like "The Seahawks just got
> the stuffings kicked out of them by the hapless Dolphins..." and then takes
> his perverse ire out on some unsuspecting newbie.

> It's kind of tragic, really.

I remember the first time User923005 posted his real name... my jaw dropped
to the floor - I'd never thought of anything like that!

In the light of that experience: Dann, you're probably right about him.

Arjan Bokx



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
On Sun, 9 Jan 2000 19:52:15 -0800, "Jeff D. Hamann"

Quote:

>I'm curious to know if there's a general sentiment regarding the use of
>floats vs. doubles. I normally use doubles out of habit even though there no

As a general rule I always use doubles to avoid any precision problems
(even trivial operations can give rise to amusing results).

As for integer types, I use short or long, never int except as a loop
variable or very temporary variable. And  I usually comment my use of
int to explain why its safe in this instance.

This is because I once spent a considerable time porting a program
from one machine to another with different sized ints. Since the input
read and the output generated binary files, the difference in size was
incredibly important and required every single occurence of "int" to
be checked to see if it was a long or short, irrespective of where it
was used. To make it more amusing the two architectures were
opposite-endian so that every variable had to have its bytes swapped
too (the files had to be created on one and read on the other
architecture without issues...).
Mark McIntyre

C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
I'm inclined to agree but it still makes for amusing reading.



Quote:

>I remember the first time User923005 posted his real name... my jaw dropped
>to the floor - I'd never thought of anything like that!

>In the light of that experience: Dann, you're probably right about him.

Mark McIntyre

C- FAQ: http://www.eskimo.com/~scs/C-faq/top.html



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs
On Mon, 10 Jan 2000 13:03:23 -0800, "Dann Corbit"

Quote:


> [snip]
> > > BTW, killfile User923005 and your noise level will drop dramatically.

> > User923005 is one of the most courteous and helpful posters on the whole
> of
> > Usenet. Get off his case. I happen to know he's considering legal action
> > against you for defamation of character.

> You don't know this guy like I do.  I happen to know him personally.  He
> sits in his bathrobe, quaffing a "Sam Adams" and gets this funny{*filter*}-eyed

        [snip]

Is that Sam Adams light or dark, and did he save one for me?

Jack Klein
--
Home: http://www.*-*-*.com/



Fri, 28 Jun 2002 03:00:00 GMT  
 floats/shorts vs double/longs

Quote:


> > No, the correct data type for Jeff is array [32] of unsigned char.
> With
> > enough of those (each with a massive 128 (or more!) bits)
> ....

> Usually more than 255 bits, I think.  But don't bother to post
> a reply if I'm wrong, since I don't actually have the time or
> patience to read this newsgroup.

You will, I am sure, forgive me for replying that you are correct. I had
[16] originally, changed it for no good reason, and didn't propagate the
change thoroughly. Recently my typing is going downhill... (I wrote 'unix'
recently in an email, when I meant 'unique')

Apologies.

--
Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.

"Using an undefined-behavior-induced crash as a program's intended
error-checking mechanism strikes me as a spectacularly misguided strategy"
- Steve Summit, 7 Jan 2000.



Sat, 29 Jun 2002 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. short, long, float, and double portability

2. float/int vs. double/long

3. epsilon for float, double long double

4. short/long/long long Formatting questions

5. Need function to convert float/double/long to string using a specified format

6. 8-byte double long integer to floating point?

7. Q?: double|float <-> long

8. Q?: double|float <-> long|int portability

9. Long long and long double

10. long double in c vs. fortran

11. 32-bit shorts (was a long long title)

12. float vs double in function args

 

 
Powered by phpBB® Forum Software