473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

faster double to 32.32 fixed?

I have a platform that does not store IEEE doubles, but swaps
upper/lower 4 bytes in comparison to x86. Anyway, I solved the problem
by converting my double to 32.32 fixed point like this:

inline sll dbl2sll(double dbl)
{
return (sll)(dbl * (double)(1LL<<32LL));
}

which, however is quite expensive, since the platform has no floating
point processor. Is there any faster way of doing this?

--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}

Feb 12 '07 #1
4 1818
Gernot Frisch wrote:
I have a platform that does not store IEEE doubles, but swaps
upper/lower 4 bytes in comparison to x86. Anyway, I solved the problem
by converting my double to 32.32 fixed point like this:

inline sll dbl2sll(double dbl)
{
return (sll)(dbl * (double)(1LL<<32LL));
}

which, however is quite expensive, since the platform has no floating
point processor. Is there any faster way of doing this?
You can write platform specific code by making a union contains the
double and a structure containing unsigned characters and probably other
integer types to allow you access to the binary representation. You
will probably do some masking and shifting based on the exponent.

--
Thad
Feb 12 '07 #2

"Thad Smith" <Th*******@acm.orgschrieb im Newsbeitrag
news:45***********************@auth.newsreader.oct anews.com...
Gernot Frisch wrote:
>I have a platform that does not store IEEE doubles, but swaps
upper/lower 4 bytes in comparison to x86. Anyway, I solved the
problem by converting my double to 32.32 fixed point like this:

inline sll dbl2sll(double dbl)
{
return (sll)(dbl * (double)(1LL<<32LL));
}

which, however is quite expensive, since the platform has no
floating point processor. Is there any faster way of doing this?

You can write platform specific code by making a union contains the
double and a structure containing unsigned characters and probably
other integer types to allow you access to the binary
representation. You will probably do some masking and shifting
based on the exponent.

is there any way to determine the float layout at compile time?
Feb 14 '07 #3
Gernot Frisch wrote On 02/14/07 08:31,:
"Thad Smith" <Th*******@acm.orgschrieb im Newsbeitrag
news:45***********************@auth.newsreader.oct anews.com...
>>Gernot Frisch wrote:
>>>I have a platform that does not store IEEE doubles, but swaps
upper/lower 4 bytes in comparison to x86. Anyway, I solved the
problem by converting my double to 32.32 fixed point like this:

inline sll dbl2sll(double dbl)
{
return (sll)(dbl * (double)(1LL<<32LL));
}

which, however is quite expensive, since the platform has no
floating point processor. Is there any faster way of doing this?

You can write platform specific code by making a union contains the
double and a structure containing unsigned characters and probably
other integer types to allow you access to the binary
representation. You will probably do some masking and shifting
based on the exponent.

is there any way to determine the float layout at compile time?
To the best of my knowledge, no.

If the macro __STDC_IEC_559__ is defined, the compiler claims
to use IEEE floating-point. But that's not of much help to you
because it still doesn't tell you what the various bits of a
float or double or long double signify when you manipulate them
as an array of unsigned char, for example.

Your best bet is to study the various platforms of interest
and #define a platform-specific macro for each, indicating what
you've learned about the floating-point formats. Then test those
macros inside dbl2sll() and similar functions. You could probably
write a "helper" program that would study what some selected
floating-point values look like when viewed as unsigned char[]
and then output the appropriate set of #define lines; you'd
run this program ahead of time and direct its output to a .h file
to be #include'd in the "real" build.

--
Er*********@sun.com
Feb 14 '07 #4

"Eric Sosman" <Er*********@sun.comschrieb im Newsbeitrag
news:1171467206.32458@news1nwk...
You could probably
write a "helper" program that would study what some selected
floating-point values look like when viewed as unsigned char[]
and then output the appropriate set of #define lines; you'd
run this program ahead of time and direct its output to a .h file
to be #include'd in the "real" build.
Great idea. I'll do that.
Feb 15 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: ajikoe | last post by:
def f(x,y): return math.sin(x*y) + 8 * x I have code like this: def main(): n = 2000 a = zeros((n,n), Float) xcoor = arange(0,1,1/float(n)) ycoor = arange(0,1,1/float(n))
98
by: jrefactors | last post by:
I heard people saying prefix increment is faster than postfix incerement, but I don't know what's the difference. They both are i = i+1. i++ ++i Please advise. thanks!!
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
11
by: bill | last post by:
I am trying to figure out if I can use sse to help execute arithmetic operations faster. I have 900 values that must each be scaled with a divide and multiply. This happens repeatedly. Any examples...
1
by: Shane | last post by:
I have to do a lot of calculations when leaving certain controls. Somewhere along the order of 800 to 1000 fields. I'm considering translating all of the numeric fields that are in a string...
8
by: Scott Emick | last post by:
I am using the following to compute distances between two lat/long coordinates for a store locator - (VB .NET 2003) it seems to take a long time to iterate through like 100-150 locations -...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
2
by: Markus Dehmann | last post by:
I have two integers i1 and i2, the second of which is guaranteed to be between 0 and 99, and I encode them into one double: double encoded = (double)i1 + (double)i2 / (double)100; So, for...
48
by: istillshine | last post by:
When I used gprof to see which function consumed most running time, I identified the following one. sz was less than 5000 on average, but foo had been called about 1,000,000 times. I have tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.