473,406 Members | 2,710 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,406 software developers and data experts.

Floating-Point Constant with Payload

Hi,

I'm looking for a general purpose way of initializing a floating-point
constant with an arbitrary bit pattern using C99. For example,

const unsigned int x=0x3f800000U; //assume 32-bits
const float y=*(float*)&x; //assume 32-bit single-precision IEEE754

Compiling this code on GCC generates the error "initializer element is
not constant". I can enter plus/minus zero, finites, infinites (using
1.0/0.0 and -1.0/0.0), but NaNs have me stumped. How do I get a
constant NaN with a specific payload? nan() looked promising until I
realized that it returns a variable. Any ideas?

Thanks,
Jon
Jun 27 '08 #1
1 1699
On Sun, 20 Apr 2008 09:49:01 -0700, Jon Sargeant <de*****@cox.net>
wrote:
>Hi,

I'm looking for a general purpose way of initializing a floating-point
constant with an arbitrary bit pattern using C99. For example,

const unsigned int x=0x3f800000U; //assume 32-bits
const float y=*(float*)&x; //assume 32-bit single-precision IEEE754

Compiling this code on GCC generates the error "initializer element is
not constant". I can enter plus/minus zero, finites, infinites (using
1.0/0.0 and -1.0/0.0), but NaNs have me stumped. How do I get a
constant NaN with a specific payload? nan() looked promising until I
realized that it returns a variable. Any ideas?
Answered in alt.comp.lang.c. Please don't post separate messages to
multiple newsgroups. If you want wide dissemination, post a single
message to all the groups at once (using multiple addresses).
Remove del for email
Jun 27 '08 #2

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

Similar topics

1
by: George Hester | last post by:
At the time this suggestion was made I didn't have the wherewithall to even attempt it. But over time I learned enough to make a stab at it. Let just say the foating DIV had to provide the same...
3
by: JHR | last post by:
Hey all, I'm trying to make a sidebar box float to the right of various items, and for those items to wrap if a user shrinks his browser window. Instead, in every browser I've tried except for...
12
by: meltedown | last post by:
I would like the floating divs to float and then the header to come after them , on the left. That's what I thought clearing the floats was for, but in this example, the header is to the right of...
2
by: Abhishek | last post by:
I am creating an application in C# wherein I require to add a toolbar. that is no problem and that is done as well. What I need now is that the toolbar that i insert should be a floating toolbar...
1
by: buliwyf_23 | last post by:
I have this: CSize sz; sz.cx = dwOutX1; sz.cy = dwOutY1; CPoint pt(sz); ClientToScreen(&pt);
6
by: Usenet | last post by:
I might be being silly here. On my links page I've got a whole load of floating boxes, which I'm really pleased with. But then I want the footer to be *below* them. On my current site...
1
by: hendrakieran | last post by:
Hi Guys, I'd like to get some help regarding creating a floating window with the following scenario: * I have index.html which is contains the frameset definition: <html> <head> </head>
2
by: Qiang | last post by:
Those who have used Google notebook may notice that google notebook displays the notes in a small floating window of the browser. I have tried to create a similar floating window, but with no luck....
0
by: gdrenfrew | last post by:
I'd like to know if it is possible to stop the parent application of a floating form becoming active when the controls on the floating form are clicked? I've got a large application, with multiple...
6
by: Jeremy | last post by:
I've got a floating div which becomes visible when a link is clicked. I want the div to be hidden when the user clicks anywhere on the page except for whithin the div. What is the best way to do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.