help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: converting int 2 real and vice versa


From: Daniel Heiserer
Subject: Re: converting int 2 real and vice versa
Date: Thu, 03 Sep 1998 08:58:30 +0200

> | I would like to convert integers to real and vice versa.
> | That looks strange for somebody working with octave which handles only
> | doubles.
> | The background is the following.
> |
> | I have a binary-file  containing 4 byte words integers and floats.
> | I want to read it in with ONE fread command (!performance) into an
> | integer stream.
> |
> | Of course not all are integers, most of them are floats. In C you can
> | find that easily out by just looking at the value: I know that
> | everything which is bigger than a certain value and smaller than that
> | value represents a float. In Fortran I can share the stack via a COMMON

sorry I meant EQUIVALENCE

> | definition or in C I can do similar things with pointers or units. So I
> | can get the float value out of the integer value and vice versa.
> | Can I "transform" octaves data with a similar command?
> 
> Do the float and integer values appear in a regular pattern, or can
> you only tell which is which ones are supposed to be integers by
> looking at the values?  If they appear in regular patterns, you might
> be able to take advantage of the `skip' parameter for fread to read
> them efficiently.  If you can only tell by looking at the values, I
> don't have a good solution for you.

Unfortunately I don't know what it is as long as I don't look at the
value. Else I could specify on the fread what I want to read. Probably
the best thing is writing a C-code translating all the stuff into
doubles with the right conversion:
// As far as I know that works for IEEE-be and IEEE-le 
// No idea about cray formats
// all the values are represented by a 4byte-word.
// read the 4byte-word into a signed integer my_int
// then make the decision
if (my_int>limit || my_int<-limit){
        my_doub=equivalence(my_int);    
}
else{
        my_doub=(double) my_int;
}
It would be nice to do something like that in octave.

Thanks for your help. Any more ideas?

Does anybody know how a 4byte-word float is decoded in IEEE-le/-be??
I looked at the bitpatterns, byte I still dont have the solution. Seems
to be a little difficult.



-- 
Mit freundlichen Gruessen
                                 Daniel Heiserer
-----
--------------------------------------------------------------
Daniel Heiserer, BMW AG, Knorrstrasse 147, 80788 Muenchen
Abteilung EK-20
Tel.: 089-382-21187, Fax.: 089-382-42820
mailto:address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]