473,503 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 byte float in MSVC++

Hi, I'm running out of memory storing a large float array. One
acceptable workaround would be to reduce the float precision by
switching from the default, which is 4 bytes long, to a smaller one -
say, 2 bytes.

I'm using MSVC++ 6.0 and don't see any way to do this. Perhaps MS does
not provide a 2 byte float...? Appreciate your advice. Thanks :)

Oct 18 '05 #1
6 7282
Hi,
Is there anyway I could see the code? MSVC++ 6, is my favoured Editor, I
refuse to give it up.

The Code Master
Th*************@hotmail.com

<sp******@yahoo.com> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
Hi, I'm running out of memory storing a large float array. One
acceptable workaround would be to reduce the float precision by
switching from the default, which is 4 bytes long, to a smaller one -
say, 2 bytes.

I'm using MSVC++ 6.0 and don't see any way to do this. Perhaps MS does
not provide a 2 byte float...? Appreciate your advice. Thanks :)

Oct 18 '05 #2
On 17 Oct 2005 19:58:56 -0700, sp******@yahoo.com wrote in
comp.lang.c++:
Hi, I'm running out of memory storing a large float array. One
acceptable workaround would be to reduce the float precision by
switching from the default, which is 4 bytes long, to a smaller one -
say, 2 bytes.

I'm using MSVC++ 6.0 and don't see any way to do this. Perhaps MS does
not provide a 2 byte float...? Appreciate your advice. Thanks :)


You're not going to find any conforming C++ compiler with a 16-bit
float. It doesn't meet the language requirements. Perhaps you need
to rethink your implementation.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Oct 18 '05 #3
OpenEXR has a fairly good 16-bit floating point type implementation in
C++. You cannot use it as drop-in replacement to 32-bit floating point,
though, for starters the range of values that can be stored is very
small. Works great for normalized or near normalized values (for color
for example this works great).

The implementation is same the Cg, HLSL and GLSL use, but it isn't
standard.. just de-facto standard. :)

Oct 18 '05 #4
persenaama wrote:
OpenEXR has a fairly good 16-bit floating point type implementation in
C++. You cannot use it as drop-in replacement to 32-bit floating point,
though, for starters the range of values that can be stored is very
small. Works great for normalized or near normalized values (for color
for example this works great).

The implementation is same the Cg, HLSL and GLSL use, but it isn't
standard.. just de-facto standard. :)


Would the OP consider fixed point? If so, s/he could use 16-bit ints
(short ints on many platforms). Without delving into the OpenEXR, I'm
guessing that it would incur a more serious performance hit than fixed
point calculations since it would require emulation software rather
since hardware support for 16-bit floats is generally unavailable. Of
course, performance may not be an issue for the OP.

Cheers! --M

Oct 18 '05 #5
mlimber wrote:

Would the OP consider fixed point? If so, s/he could use 16-bit ints
(short ints on many platforms). Without delving into the OpenEXR, I'm
guessing that it would incur a more serious performance hit than fixed
point calculations since it would require emulation software rather
since hardware support for 16-bit floats is generally unavailable. Of
course, performance may not be an issue for the OP.

That's an interesting suggestion. The float values I require are
strictly between 0.0 and 1.0. An unsigned short has range 0 to 65536,
so if I were to scale the floats into this range and cast to unsigned
short I would have an effective precision of 1.5e-5. I think that is
probably adequate, I'll try it - thanks for your help :)

Oct 18 '05 #6

sp******@yahoo.com wrote:
mlimber wrote:

Would the OP consider fixed point? If so, s/he could use 16-bit ints
(short ints on many platforms). Without delving into the OpenEXR, I'm
guessing that it would incur a more serious performance hit than fixed
point calculations since it would require emulation software rather
since hardware support for 16-bit floats is generally unavailable. Of
course, performance may not be an issue for the OP.

That's an interesting suggestion. The float values I require are
strictly between 0.0 and 1.0. An unsigned short has range 0 to 65536,
so if I were to scale the floats into this range and cast to unsigned
short I would have an effective precision of 1.5e-5. I think that is
probably adequate, I'll try it - thanks for your help :)


It's actually a widely used suggestion especially in scientific data
storage where you typically know the range of data and you have some
fixed significant digits. Take for example an instrument measuring sea
surface temperature to an accuracy of 10^-4 degrees. You can typically
calculate a range of values the temperature can take in a "specific"
body of water. You then use a linear function y = mx + b to scale the
floating point data to some integer type. This is good especially in
storing large data sets where you can cut double or single precision
down to int32 or int16 storage size. When we stored data in HDF files,
we would specify the m and b (slope and intercept) as attributes to
recover the data.

Oct 18 '05 #7

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

Similar topics

9
9674
by: franzkowiak | last post by:
Hello, I've read some bytes from a file and just now I can't interpret 4 bytes in this dates like a real value. An extract from my program def l32(c): return ord(c) + (ord(c)<<8) +...
235
11492
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
16
16387
by: Khuong Dinh Pham | last post by:
I have the contents of an image of type std::string. How can I make a CxImage object with this type. The parameters to CxImage is: CxImage(byte* data, DWORD size) Thx in advance
11
3769
by: Joriveek | last post by:
I have a float variable like 123456789 I want to right truncate this and only display say only 8 right most values all the time or otherwise filled by zeros if it is less than 8 digits, do you...
8
18856
by: Kenny ODell | last post by:
I do not know how to convert from a byte array to a float, and back again. I read data from a serial port into a byte (entire command structure which I parse). I am able to sift the data and...
7
7174
by: Mario M. Mueller | last post by:
Hi, I have a binary file containing 3 byte float values (big endian). How can I read them into python? The struct module does not work, since it expects 4 byte floats. Any hints? Mario
3
3384
by: DWilli3501 | last post by:
I have two short programs that use floating point numbers. The first gives an incorrect result. By simply placing a "cout" (or any executable line) in the correct location of the program I get a...
9
5150
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
12
13507
by: Peter | last post by:
Trying to convert string to byte array. the following code returns byte array of {107, 62, 194, 139, 64} how can I convert this string to a byte array of {107, 62, 139, 65} ...
0
7261
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
7315
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...
0
7445
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.