Go to Post theres nothing more macho than something made entirely out of diamond plate. - Dan9874123 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 30-03-2011, 21:54
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Regarding The Library And Variable Usage.

Okay, I was wondering if anyone has any idea why the WPILib uses doubles instead of floats. It makes more sense to me to use floats over doubles. I find it very "costly" to use 32 extra bits. Also, why are variables like PWM ints? Why not a short? Sure, if java had unsigned variables, I would have used uint_8 (unsigned byte) instead.

Now, keep in mind, this is an embedded system. It is not a good idea to spam usage of doubles IMHO. Even if we have like 64 mb of ram. I know, you can fill that up with over 6 million doubles, but it still bothers me.
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #2   Spotlight this post!  
Unread 30-03-2011, 22:14
EricVanWyk EricVanWyk is offline
Registered User
no team
 
Join Date: Jan 2007
Rookie Year: 2000
Location: Boston
Posts: 1,597
EricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond reputeEricVanWyk has a reputation beyond repute
Send a message via AIM to EricVanWyk
Re: Regarding The Library And Variable Usage.

Why not? Unless you get actual gains by going with smaller data types, it isn't worthwhile.

You'd be surprised at the relative costs of things in modern processors. I'm not a PPC expert, but I did do a lot of assembly level optimization of on the ARM (THUMB2) platform. Using U8s instead of U32s can often be slower, as memory access is word aligned.

Don't optimize unless you have to and will actually benefit.
Reply With Quote
  #3   Spotlight this post!  
Unread 30-03-2011, 22:17
MikeE's Avatar
MikeE MikeE is offline
Wrecking nice beaches since 1990
no team (Volunteer)
Team Role: Engineer
 
Join Date: Nov 2008
Rookie Year: 2008
Location: New England -> Alaska
Posts: 381
MikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond repute
Re: Regarding The Library And Variable Usage.

Quote:
Originally Posted by davidthefat View Post
Okay, I was wondering if anyone has any idea why the WPILib uses doubles instead of floats. It makes more sense to me to use floats over doubles. I find it very "costly" to use 32 extra bits. Also, why are variables like PWM ints? Why not a short? Sure, if java had unsigned variables, I would have used uint_8 (unsigned byte) instead.

Now, keep in mind, this is an embedded system. It is not a good idea to spam usage of doubles IMHO. Even if we have like 64 mb of ram. I know, you can fill that up with over 6 million doubles, but it still bothers me.
I spent several years cramming fairly sophisticated signal processing and pattern matching algorithms onto embedded systems, and one of the lessons I took from the experience is that the embedded world doesn't always work the way one would naively expect.
While integer arithmatic was always preferable for speed we encountered several situations where floating point calculation was faster using double precision than single precision floats due to implementation details in support libraries. And in almost all cases of consumer electronics memory access speed was a more significant practical constraint that raw number crunching.

IMHO the primary purpose of the library is clarity and utility for programmers of various abilities. Bit cramming efficiency should be at best a secondary consideration.
Reply With Quote
  #4   Spotlight this post!  
Unread 04-04-2011, 14:58
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Regarding The Library And Variable Usage.

I get it, after reading the PPC Instruction Set Reference Manual, the PPC's Floating Point Registers are 64 bit registers. In other words, if I were to use single precision floating points, then the processor has to shove that to one 32 bit side of the register and fill the rest with 0's. I get it, that takes more effort than just shoving a double in there. The single precisions are always converted to doubles anyway.

Reading the technical manuals really do help...

So there was a method to their madness...
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.

Last edited by davidthefat : 04-04-2011 at 15:03.
Reply With Quote
  #5   Spotlight this post!  
Unread 04-04-2011, 16:17
MikeE's Avatar
MikeE MikeE is offline
Wrecking nice beaches since 1990
no team (Volunteer)
Team Role: Engineer
 
Join Date: Nov 2008
Rookie Year: 2008
Location: New England -> Alaska
Posts: 381
MikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond repute
Re: Regarding The Library And Variable Usage.

Quote:
Originally Posted by davidthefat View Post
So there was a method to their madness...
In the most part the libraries are written by professional software engineers, so I start with the assumption that there is a good reason for design decisions. (Always allowing for the possibility of bugs occurring in complex systems of course.)
Reply With Quote
  #6   Spotlight this post!  
Unread 04-04-2011, 21:25
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Regarding The Library And Variable Usage.

Not to beat a dead horse, but if I recall, the singles are loaded into the registers as doubles. That doesn't mean adding 32 zeroes on the end, but it means changing a (23+1,8,1) format into a (52+1,12,1). This means that the base two exponent uses 12 bits rather than 8, and the mantissa is 52 with 1 implicit bit instead of 23 bits. Both formats are described by the IEEE 754 format -- a pretty fascinating read.

Greg McKaskle
Reply With Quote
  #7   Spotlight this post!  
Unread 04-04-2011, 21:32
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: Regarding The Library And Variable Usage.

Quote:
Originally Posted by Greg McKaskle View Post
Not to beat a dead horse, but if I recall, the singles are loaded into the registers as doubles. That doesn't mean adding 32 zeroes on the end, but it means changing a (23+1,8,1) format into a (52+1,12,1). This means that the base two exponent uses 12 bits rather than 8, and the mantissa is 52 with 1 implicit bit instead of 23 bits. Both formats are described by the IEEE 754 format -- a pretty fascinating read.

Greg McKaskle
Aha, thank you, I knew something sounded wrong about my statement. i read about that a couple days ago!
__________________
Do not say what can or cannot be done, but, instead, say what must be done for the task at hand must be accomplished.
Reply With Quote
  #8   Spotlight this post!  
Unread 04-04-2011, 22:16
MikeE's Avatar
MikeE MikeE is offline
Wrecking nice beaches since 1990
no team (Volunteer)
Team Role: Engineer
 
Join Date: Nov 2008
Rookie Year: 2008
Location: New England -> Alaska
Posts: 381
MikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond reputeMikeE has a reputation beyond repute
Re: Regarding The Library And Variable Usage.

Quote:
Originally Posted by Greg McKaskle View Post
Both formats are described by the IEEE 754 format -- a pretty fascinating read.
Spotlighted!
You've provided an outstanding working definition of an Engineer (EE/ECE sub-species).
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:16.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi