Sponsored Content
Top Forums Programming Strange value of the double type variable: -nan(0x8000000000000) Post 302903832 by 915086731 on Friday 30th of May 2014 03:25:22 AM
Old 05-30-2014
Strange value of the double type variable: -nan(0x8000000000000)

I am confused by the value of "currdisk->currangle" after adding operation. Initially the value of "currdisk->currangle" is 0.77500000000000013, but after adding operation, it's changed to "-nan(0x8000000000000)", Can anyone explain ? Thanks! The following is the occasion of gdb debugging.

Code:
3338          currdisk->currangle += (simtime - seg->time) / currdisk->rotatetime;
(gdb) p currdisk->currangle
$28 = 0.77500000000000013
(gdb) p (simtime - seg->time) / currdisk->rotatetime
$29 = 0.00833333333333325
(gdb) p (simtime - seg->time) 
$30 = 0.092592592592591672
(gdb) p currdisk->rotatetime
$31 = 11.111111111111111
(gdb) n

(gdb) p currdisk->currangle 
$32 = -nan(0x8000000000000)
(gdb) p/x (char[8])currdisk->currangle 
$52 = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8, 0xff}
(gdb)

Then I change
currdisk->currangle += (simtime - seg->time) / currdisk->rotatetime ;
to
double tmp1 = (simtime - seg->time) / currdisk->rotatetime;
currdisk->currangle += tmp1;

The value of currdisk->currangle is normal. Can anyone explain the confusing phenomenon ?

---------- Post updated 05-30-14 at 02:25 AM ---------- Previous update was 05-29-14 at 10:56 PM ----------

All are double type.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem with variable type

Dear All, I am trying to write an script to calculate geometric centre of selected residues of a protein structure. Say I have a PDB file (a text containing the x, y, and z coordinates of atoms of a protein). I want to extract the X coordinates of the atoms belonging to the interested residues... (2 Replies)
Discussion started by: siavoush
2 Replies

2. Shell Programming and Scripting

how to get type of variable in perl

hello all how can i get the type of variable in perl like typeof(var); in javascript for instance ? to know if the variable is int or string ? (2 Replies)
Discussion started by: umen
2 Replies

3. Shell Programming and Scripting

getting type of variable

Hello: Is there any way to tell the type of a passed or entered variable, if it is a string or integer,...etc. Thanks a lot (2 Replies)
Discussion started by: aladdin
2 Replies

4. Shell Programming and Scripting

Perl variable type assessment

Hello experts, How we can find out,that what is type of a scalar variable? i.e a scalar var contain a number or a string. Thanks in advance. (8 Replies)
Discussion started by: Zaxon
8 Replies

5. Shell Programming and Scripting

Strange variable comparison result in awk

So, I'm making a little awk script that generates a range-based histogram of a set of numbers. I've stumbled onto a strange thing. Toward the end of the process, I have this test: if ( bindex < s ) "bindex" is the "index" of my "bin" (the array element that gets incremented whenever a... (2 Replies)
Discussion started by: treesloth
2 Replies

6. Shell Programming and Scripting

What is a type of this variable?

I have a question about the type of this variable checkU= sudo cat /etc/passwd: grep $uname: wc -l I write a script to check the existent of username that get from the keyboard. If there is no username,it will create the username else it show the 'Duplicate name" message. The problem is it... (4 Replies)
Discussion started by: thsecmaniac
4 Replies

7. Shell Programming and Scripting

Strange type mistake?!

Hi, I want to start MY_PROGRAM in a bash script with additional parameters given in the CONFIGURATION_ARRAY. IFS="'" CONFIGURATION_ARRAY=( '-N 0 -m 0' '-N 0 -m 1' ) for configuration in ${CONFIGURATION_ARRAY} do //DEBUG N=${configuration%-*} //-N 0 M=-${configuration##*-} //-m 0... (5 Replies)
Discussion started by: xraystorm
5 Replies

8. Shell Programming and Scripting

Strange Phenomena with records filed in variable

Trying to find out whether there is a limit for the number of records that can be stored in a variable I set up this small script: #!/usr/bin/ksh for ((i = 1; i < 21; i++)) do n=$(($i*100)) echo "Trying $n records:" recs=$(head -$n error.log) echo "$recs" | wc done ... (9 Replies)
Discussion started by: Cochise
9 Replies

9. Red Hat

Double data type C Red Hat platform problem

I'm converting a binary file to ASCII using c code. The folllowing block of code prints correct double value 00000.000000000 on HPUNIX platform. longi double; /* C79 - Price Per Minute */ memcpy(&longi,&rbuff,8); fprintf(wfp,"%015.9f ",longi); prints : 00000.000000000 ... (6 Replies)
Discussion started by: krk
6 Replies

10. Shell Programming and Scripting

Bash - concatenate string - strange variable scoping

Hello, I am trying to concatenate a string in a bash script like this: runCmd="docker run -e \"IMAGE_NAME=$IMAGE_NAME\" " env | grep "$ENV_SUFFIX" | while read line; do envCmd="-e \"${line}\" " runCmd=$runCmd$envCmd echo $runCmd # here concatenation works fine done echo... (3 Replies)
Discussion started by: czabak
3 Replies
NAN(3)							   BSD Library Functions Manual 						    NAN(3)

NAME
nan, nanf, nanl -- quiet NaNs LIBRARY
Math Library (libm, -lm) SYNOPSIS
#include <math.h> double nan(const char *s); float nanf(const char *s); long double nanl(const char *s); DESCRIPTION
The NAN macro expands to a quiet NaN (Not A Number). Similarly, each of the nan(), nanf(), and nanl() functions generate a quiet NaN value without raising an invalid exception. The argument s should point to either an empty string or a hexadecimal representation of a non-nega- tive integer (e.g., "0x1234".) In the latter case, the integer is encoded in some free bits in the representation of the NaN, which some- times store machine-specific information about why a particular NaN was generated. There are 22 such bits available for float variables, 51 bits for double variables, and at least 51 bits for a long double. If s is improperly formatted or represents an integer that is too large, then the particular encoding of the quiet NaN that is returned is indeterminate. COMPATIBILITY
Calling these functions with a non-empty string isn't portable. Another operating system may translate the string into a different NaN encoding, and furthermore, the meaning of a given NaN encoding varies across machine architectures. If you understood the innards of a par- ticular platform well enough to know what string to use, then you would have no need for these functions anyway, so don't use them. Use the NAN macro instead. SEE ALSO
fenv(3), ieee(3), isnan(3), math(3), strtod(3) STANDARDS
The nan(), nanf(), and nanl() functions and the NAN macro conform to ISO/IEC 9899:1999 (``ISO C99''). BSD
December 16, 2007 BSD
All times are GMT -4. The time now is 02:07 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy