Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Sun C 5.8 weird divide by zero result

807575Mar 29 2010 — edited Mar 29 2010
I am trying to port an extremely large C program from a Sun OS 5.10 system to Linux. The program on the Sun machine was compiled using the Sun C 5.8 compiler. While trying to debug why the results are different on the two systems, I discovered that the code on the Sun machine returns zero when a number is being divided by 0, rather than NAN or inf as I would expect.

For example using DBX, I stepped through the following code and temp was computed to be 0.0,

(dbx) next
stopped in initialize_planet_geometry at line 3125 in file "position_att.c"
3125 temp = v->earth_radius_pole / v->earth_radius_equator;
(dbx) list
3125 temp = v->earth_radius_pole / v->earth_radius_equator;
3126 rpole_2_over_requator_2 = temp * temp;
3127 v->earth_ecc_2 = 1.0 - rpole_2_over_requator_2;
3128
3129 v->requator_2_over_rpole_2 = 1.0 / rpole_2_over_requator_2;
3130
3131 v->earth_flattening = 1.0 - v->earth_radius_pole /
3132 v->earth_radius_equator;
3133
3134 SET_VECTOR( v->earth_rot_vec, 0.0, 0.0, v->earth_rot_rate );
(dbx) print v->earth_radius_equator
v->earth_radius_equator = 0.0
(dbx) print v->earth_radius_pole
v->earth_radius_pole = 0.0
(dbx) next
stopped in initialize_planet_geometry at line 3126 in file "position_att.c"
3126 rpole_2_over_requator_2 = temp * temp;
(dbx) print temp
temp = 0.0

Can anyone explain how this can happen?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2010
Added on Mar 29 2010
1 comment
93 views