- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- double to unsigned int typecasting is failing in H...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2013 06:42 PM - last edited on 04-29-2013 06:15 PM by Maiko-I
04-28-2013 06:42 PM - last edited on 04-29-2013 06:15 PM by Maiko-I
double to unsigned int typecasting is failing in HPUX itanium 11.31
Hi All,
I have come across a very surprising behaviour of s programme in HPUX itanium11.31
The conversion from double to unsigned int is failing under certain circumstances and making it zero. Howevr the same code works in HPUX itanium 11.23.
Below is the sample programme which is failing.
=====================
#include<stdio.h>
int main()
{
double dd = -2147483648.000000;
unsigned int k = dd;
printf("%lf",dd);
printf(":::::");
printf("%d",k); /* here is the problem after assignment value of k is becoming zero
return 1;
}
====================================
How ever if I am converting the double to long and then that long again gets converted to unsigned it, it works. sample programme:
#include<stdio.h>
int main()
{
double dd = -2147483648.000000;
long ll = dd;
unsigned int k = ll;
printf("%lf",dd);
printf(":::::");
printf("%d",k);
return 1;
}
==============================================
In our application we have been using the double to unsigned it many palces from long time ( or from HPUX itanium 11.23). However the code is breaking only in HPUX itanium 11.31 .
Any patch is mising in 11.31 version ?
Please put some light in this direction.
Thanks
Dibendusah
P.S. This thread has been moved from HP-UX > Patches to HP-UX > languages - HP Forums Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2013 03:06 AM
04-29-2013 03:06 AM
Re: double to unsigned int casting is failing in HP-UX Integrity 11.31
What versions of aCC6 are you using on 11.23 and 11.31?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2013 10:08 PM - edited 05-01-2013 08:39 PM
04-29-2013 10:08 PM - edited 05-01-2013 08:39 PM
Re: double to unsigned int casting is failing in HP-UX Integrity 11.31
>The conversion from double to unsigned int is failing under certain circumstances and making it zero.
This a correct behavior for your undefined code. A negative double is NOT valid to be assigned to an unsigned integral type and has undefined behavior. For Integrity it causes an IEEE Invalid operation with the result of 0x8000000000000000ULL, which is truncated to 0. Linking with +FPV will cause a runtime SIGFPE.
>the same code works in HP-UX Integrity 11.23.
Not that I can see. All aCC5 and aCC6 versions do the same. Only PA-RISC does what you said.
(Unless you were running it under Aries.)
The difference is that IA64 contains an instruction to convert directly from double to unsigned long long.
But PA-RISC at one time (PA1.0) didn't have that instruction and unfortunately it was never used after it was added.
Note these formats aren't valid:
printf("%lf", dd);
printf("%d", k);
In the first the "l" is ignored, so it should just be %f. The second should be %u for unsigned.