Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][tlug] issues with format of double (or IEEE754)
- Date: Wed, 26 Jul 2006 14:59:07 +0200
- From: Michal Hajek <hajek1@example.com>
- Subject: [tlug] issues with format of double (or IEEE754)
- User-agent: Mutt/1.5.11+cvs20060403
Hello :) I appologize if this is not a sort of "only linux related question". Still I believe there is some kind of relation to linux, since I do all the described actions using debian testing on an i386 mashine... I have a problem with getting a double precision number from my digital nanovoltmeter (keithley 2182A). I can comunicate with it through gpib interface and the manual says [1], that it can send 10byte data in format: (ascii header)#0 (just 64 bits) 1110010..... So after two characters, 64 zeros and ones come. The later are organised such that first 11 bits are "exponent bits" followed by 52 "fraction bits", conforming to IEEE754 format. So I use a function ibrd() [2] to read this data in a buffer defined in this way: char result_normal_plus[17]="00000000000000000"; ... ibrd(K2182Ud,result_normal_plus,10); result_normal_plus[ibcnt]='\0'; and then I do: presult= result_normal_plus+2; where presult is a pointer to double, eg. defined as: double *presult; The problem is that if I print the number: printf("*presult: %.12f \n",*presult); I always get a number which is 4 orders of magnitude lower. For example: 0.00002 instead of 0.2 Can anyone help me to understand why it is so? Or maybe suggest a more clever [3] way of getting the result from nanovoltmeter? The compilation is done with gcc (GCC) 4.0.4 20060507 (prerelease) (Debian 4.0.3-3), using -pg -Wall flags. (-pg is for profiler info) For clarity, I once more rewrite the structure of my program: ... double *presult; char result_normal_plus[17]="00000000000000000"; ... ibrd(K2182Ud,result_normal_plus,10); result_normal_plus[ibcnt]='\0'; presult= result_normal_plus+2; printf("*presult: %.12f \n",*presult); ... Thank you for any kind of help.. :) [1] http://www.keithley.com/data?asset=15977 section 15-5 [2] http://linux-gpib.sourceforge.net/doc_html/r1811.html [3] I have implemented reading in ASCII format and than converting with atof() function, but this I prefer to avoid, since atof() takes more time than reading straight in double format (or at least I think so) Best regards Michal
- Follow-Ups:
- Re: [tlug] issues with format of double (or IEEE754)
- From: Jim
- Re: [tlug] issues with format of double (or IEEE754)
- From: Stephen J. Turnbull
- [tlug] just a quick note... more to come later :)
- From: Michal Hajek
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] I'm a glutton for punishment - Palm Pilot and Ubuntu Dapper LTS connectivity
- Next by Date: Re: [tlug] I'm a glutton for punishment - Palm Pilot and Ubuntu Dapper LTS connectivity
- Previous by thread: Re: [tlug] Disabling Removable Media
- Next by thread: Re: [tlug] issues with format of double (or IEEE754)
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links