Re: problems calculation very long numbers....
From: Yodai (yodai_at_spamnot.mail.vu)
Date: 12/09/03
- Next message: Stefan Höhne: "Re: unique numbers using srand( ) and rand( ) functions in C++[ caution long post]"
- Previous message: Chris \( Val \): "Re: fstream"
- In reply to: Karl Heinz Buchegger: "Re: problems calculation very long numbers...."
- Next in thread: Jumbo: "Re: problems calculation very long numbers...."
- Reply: Jumbo: "Re: problems calculation very long numbers...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 09 Dec 2003 15:03:48 GMT
ok... I'll try to write it better..... I get a variable that consists of
this number : 0x00201582, but I get it in two "chunks". The reason is not
important but, just so you know, I have to make a "volatile int" to a
pointer that can only be 2 bytes (compiler limitation) So what I do, I get
firs 2 bytes the the other 2 as:
varHI = 0x0020 and varLO = 0x1582 and I have to put them toguether to
multiply them by factor (which value is 0x174b) I f you get a good hexa
calculator (windows calc does not do the job since it doesn't accept 40 bit
values) the final result of this calculation is 2EB54FB16 which I have to
translate to a decimal result as 1253.8.....
When I start calculating and I multiply the values, the container for this
operation is too small (a double that can only get 32bits, long double is
not accepted by my compiler), thus not finishing the calculation and
forgeting one of the digits of the final result, the 1st one or the last one
(meaning 2EB54FB1 without the last 6 or the oposite EB54FB16 without the
first 2). That is EXACTLY where my problem is rooted. I need a way to carry
on this simple calculations so that I can use the 4.5 bytes of the result
for my conversion to decimal (which after deleting all non necessary numbers
at the mantissa will be less than 32 bits)
better? does somebody see what I mean? any solution?
Cheers....
> > Once I get this set of info I have to do some calculations with
> > it.....
> >
> > To be specific:
> >
> > if : varHI = 0x0020 and varLO = 0x1582 factor = 0x174b
> > then I should get finalresult = 1253.8149654 = 2EB54FB16
>
> What's not very clear: In which way is the input and the output related?
> I can't see an ovious formula to connect 0x0020, 0x1582, 0x174b
> with 0x2EB54FB16 (The later number by the way consists of 9 nibbles,
> thus would require 4.5 bytes)
>
> What does your hardware give to you?
> Are those already floating point numbers?
> Is the format the special hardware uses compatible or the same as your
> computer uses?
>
> > but, since double can only be 4 bytes I can only get 2EB54FB1 or
> > EB54FB16.... wether I eat up the first or the last digit which, as you
know,
> > in hexa means loosing track of the original number..... I wouldn't mind
> > loosing precission at the decimal result because I actually only need
> > finalresult = 1253.8 thus I can "eat up" 149654.....
> >
> > Here is my function to do so..... still failing, though it compiles....
> >
> > double Myfunction(void)
> > {
> > volatile int varLO = *external16bitinfoLO ;
> > volatile int varHI = *external16bitinfoHI;
> > volatile int factor = *FACTOR ;
> > double finalresult;
> >
> > finalresult = (((varHI*0x10000)+varLO)*(factor)/10000000f);
>
> That looks as if your hardware gives you some sort of fixed point
> integer ( 0 = 0.0, 1 = 1/0x174b, 2 = 2 / 0x174b, 0x174b = 1.0 , ... )
>
> What is sizeof(int) on this system. Any chance that
>
> (varHI*0x10000)+varLO)
>
> produces an overflow? Try:
> long temp = (varHI*0x10000)+varLO);
> and look at the bytes in temp. Are they correct?
>
>
> Where did you get the formula from (some documentation?)? Is it correct?
>
> --
> Karl Heinz Buchegger
> kbuchegg@gascad.at
- Next message: Stefan Höhne: "Re: unique numbers using srand( ) and rand( ) functions in C++[ caution long post]"
- Previous message: Chris \( Val \): "Re: fstream"
- In reply to: Karl Heinz Buchegger: "Re: problems calculation very long numbers...."
- Next in thread: Jumbo: "Re: problems calculation very long numbers...."
- Reply: Jumbo: "Re: problems calculation very long numbers...."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|