# Thread: Minimum value Command prompt can handle?

1. ## Minimum value Command prompt can handle?

Hi,

I am having a problem with (at least I think it is, maybe it is not) with minimum value Command prompt can handle.
For to say, that I am not a programmer, nor I have any knowledge of it. I am just using a C file a friend of mine wrote for me. Here is the code:

Code:
```#include<stdio.h>
#include<math.h>

void main(){
double f0;
double n31,n32,n33,f;
double A=0.373;
printf("# f0, f, n31, n32,n33\n");
for(f0=1.0e-26;f0<=1.0e-5;f0=f0*pow(10.0,0.02)){
n31=-2.0+floor(1.29*pow(f0,-0.25));
n32=-2.0+floor(A*pow(f0,-0.25)*(12.0)*sqrt((n31+2.0)/(11.0*n31+43.0)));
n33=-2.0+floor(A*pow(f0,-0.25)*(41.5692)*sqrt((n31+2.0)/(11.0*n31+43.0)*(n32+2.0)/

(11.0*n32+43.0)));
f=pow(13.5,1.5)*f0*pow(n31+2.0,-2.0)*pow(n32+2.0,-2.0)*(n33+2.0,-2.0);
printf("%g %g %i %i %i\n",f0,f,(int)n31,(int)n32,(int)n33);
}
}```
I am using Codeblocks to run it.
The problem I am having is with "f0" variable. Even thought it is defined to be between 1.0e-26 and 1.0e-5 the most lower value of "f0" I am getting when I run it in Codeblocks is: 1.20226e-11

http://img442.imageshack.us/img442/8139/n33fh.jpg

Why is that?
Is there some minimum value Comand prompt can handle (something like 1e-11 ?)

P.S.

I asked the same question on the Codeblocks official forum, and they told me, this is a programming, not a Codeblocks issue, and rejected to reply further more.

2. I have no idea what you mean by "minimum value Command prompt can handle".

In any event, you probably need to understand what floating point types (float and double) do. They do not represent some general real number. They are an approximation, and cannot represent all possible real values. That has lots of consequences, such as repeated addition or (as your code is doing) repeated multiplication exhibiting rounding errors, so the accuracy of calculations can reduce over time.

As a general rule, it is extremely bad practice to use a floating point variable (a float or a double) to control a for loop because of those accumulating rounding errors. It is a distinct possibility that a for loop like yours will never end.

Without knowing what your code is trying to achieve it is impossible to help you. And, to put it gently, the purpose of that code is unclear.

Rather than trying to debug code written by someone else, that you don't understand, you would be better off articulating what the code is supposed to achieve (in natural language, like English). Being able to describe what task you are trying to achieve is a MANDATORY FIRST STEP before you can hope to write/find/beg/borrow/steal code to complete that task.

Oh, and main() returns int, not void.

3. They had right at the Codeblocks forums,because this is indeed a programming issue.After some googling i found this:

Double precision values with double type have 8 bytes. The format is similar to the float format except that it has an 11-bit excess-1023 exponent and a 52-bit mantissa, plus the implied high-order 1 bit. This format gives a range of approximately 1.7E–308 to 1.7E+308 for type double.
The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision.

When we store a number at our pc,then this number it stored into some bits(or bytes).So this space is limitted.That's why we can not store every number with 100% precision.

In your program declare variable f0 as float,in code this is
Code:
`float f0;`
and remove line 5.
And in C it is common to write
Code:
`int main(void)`
so write this instead of line 4.
Also write
Code:
`return 0;`
in order to state that you program terminated successfully before the end of main.That's it after line 17.

Also run this program to see the maximum value.
Code:
```#include <float.h>//library needed for DBL_MAX
int  main(void){
printf("%g\n\n", DBL_MAX);
printf("%f\n", DBL_MAX);
return 0;
}```
My output is
Code:
```1.79769e+308

179769313486231570814527423731704356798070600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000```

4. Your program doesn't use a command prompt, and it's confusing when you use that term - please don't use it.

Every data type has limits. Check what your compiler has (and note that Codeblocks is just an IDE, NOT a compiler). You have limits specified in the header file, (usually limits.h). Check your compiler.

Looking at your program, it appears to require integer accuracy, rather than just float or double precision. There are libraries to help (Big Num from GNU utilities, comes to mind). You can always "roll your own" by using arrays of integer where each array element is a single digit of the number. It's educational to work with digits and numbers, in this way.

What are you trying to do here?

5. Thank you for such a quick and informative reply all of you.

I am apologizing for my ignorance, and am so ashamed because of it.

I am trying to extract a three variables (integer numbers): n31, n32, n33, for a specific value of "f". On top of that there is a third variable "f0" which should vary from 10^-26 to 10^-5.
So what this code should enable me is that for some "f" which I will get from my press machine and read it, I should search this C code for the same (or similar) "f" value, and read what are the values for f0, n31, n32, n33 in accordance to that "f" value.
An example: If I get a value of 5e-10 from my machine press, I will look for the some (or similar value) in C code and when I find that value I will be able to get the f0, n31, n32, n33 from it. Like this:

3.63078e-006 -5.09259e-010 27 27 28

I am I still puzzled why am I getting a negative values for "f" (-5.09259e-010 ?)

This is a structural analysis study of a piston press. The f, f0, n31, n32, n33 are coefficients needed in order for the design calculation to be done. As there are few equations with few variables, it seems writing a C code with loop and then getting the values from it is only available solution, as I did not succeed in calculating these factors by hand.

@std10093: I tried changing the parts of the code the way you told me, like this:

Code:
```#include<stdio.h>
#include<math.h>

int main(void){
float f0;
double n31,n32,n33,f;
double A=0.373;
printf("# f0, f, n31, n32,n33\n");
for(f0=1.0e-26;f0<=1.0e-5;f0=f0*pow(10.0,0.02)){
n31=-2.0+floor(1.29*pow(f0,-0.25));
n32=-2.0+floor(A*pow(f0,-0.25)*(12.0)*sqrt((n31+2.0)/(11.0*n31+43.0)));
n33=-2.0+floor(A*pow(f0,-0.25)*(41.5692)*sqrt((n31+2.0)/(11.0*n31+43.0)*(n32+2.0)/(11.0*n32+43.0)));
f=pow(13.5,1.5)*f0*pow(n31+2.0,-2.0)*pow(n32+2.0,-2.0)*(n33+2.0,-2.0);
printf("%g %g %i %i %i\n",f0,f,(int)n31,(int)n32,(int)n33);
}
}```
Still the most lower value for "f0" is around 1.2e-011.

And I also run the code you gave me (the one for the maximum value) and got something similar like you:

Code:
```1.79769e+308

17976931348623157000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000.000000

Process returned 0 (0x0)   execution time : 0.016 s
Press any key to continue.```

@Adak. Here is the content of the limits.h file I found in "C:\Dev-Cpp\include" folder. What part of it do I need to change in order to increase that lower limit of 1.2e-011?

Code:
```/*
* limits.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Functions for manipulating paths and directories (included from io.h)
* plus functions for setting the current drive.
*
* Defines constants for the sizes of integral types.
*
* NOTE: GCC should supply a version of this header and it should be safe to
*       use that version instead of this one (maybe safer).
*
*/

#ifndef _LIMITS_H_
#define _LIMITS_H_

/* All the headers include this file. */
#include <_mingw.h>

/*
* File system limits
*
* TODO: NAME_MAX and OPEN_MAX are file system limits or not? Are they the
*       same as FILENAME_MAX and FOPEN_MAX from stdio.h?
* NOTE: Apparently the actual size of PATH_MAX is 260, but a space is
*       required for the NUL. TODO: Test?
*/
#define PATH_MAX    (259)

/*
* Characteristics of the char data type.
*
* TODO: Is MB_LEN_MAX correct?
*/
#define CHAR_BIT    8
#define MB_LEN_MAX    2

#define SCHAR_MIN    (-128)
#define SCHAR_MAX    127

#define UCHAR_MAX    255

/* TODO: Is this safe? I think it might just be testing the preprocessor,
*       not the compiler itself... */
#if    ('\x80' < 0)
#define CHAR_MIN    SCHAR_MIN
#define CHAR_MAX    SCHAR_MAX
#else
#define CHAR_MIN    0
#define CHAR_MAX    UCHAR_MAX
#endif

/*
* Maximum and minimum values for ints.
*/
#define INT_MAX        2147483647
#define INT_MIN        (-INT_MAX-1)

#define UINT_MAX    0xffffffff

/*
* Maximum and minimum values for shorts.
*/
#define SHRT_MAX    32767
#define SHRT_MIN    (-SHRT_MAX-1)

#define USHRT_MAX    0xffff

/*
* Maximum and minimum values for longs and unsigned longs.
*
* TODO: This is not correct for Alphas, which have 64 bit longs.
*/
#define LONG_MAX    2147483647L

#define LONG_MIN    (-LONG_MAX-1)

#define ULONG_MAX    0xffffffffUL

/*
* The GNU C compiler also allows 'long long int'
*/
#if    !defined(__STRICT_ANSI__) && defined(__GNUC__)

#define LONG_LONG_MAX    9223372036854775807LL
#define LONG_LONG_MIN    (-LONG_LONG_MAX-1)

#define ULONG_LONG_MAX    (2ULL * LONG_LONG_MAX + 1)

/* ISO C9x macro names */
#define LLONG_MAX LONG_LONG_MAX
#define LLONG_MIN LONG_LONG_MIN
#define ULLONG_MAX ULONG_LONG_MAX

/* MSVC compatibility */
#define _I64_MIN LONG_LONG_MIN
#define _I64_MAX LONG_LONG_MAX
#define _UI64_MAX ULONG_LONG_MAX

#endif /* Not Strict ANSI and GNU C compiler */

#endif /* not _LIMITS_H_ */```

From the above code:

Code:
`#define PATH_MAX    (259)`
Is that what I need to change/increase ??

Thank you.

6. You can't CHANGE the limits - limits.h just tells you what the range is -- don't change anything in it!

So the values you look up, based on the output from the press machine, only need to be calculated ONE time, and saved to a data file. Then you can load that data into an array, sorted by the f value, and use a binary search to quickly locate the nearest/correct f value, and retrieve the other settings for f's data.

Or do you want to calculate each time you get an f value, the other data items for it, EACH time the press machine gives you a number?

How often does the press machine give you an f value?

What do you think about using integers with a larger range, instead of doubles?

7. Yes, output result (the "f") need to be calculated only one time, and for that particular project output data from this C code can be saved and used over and over again, for the same project, with different "f".
The way you described it - with search would be great, but it is also not a problem for me to visually locate it. It takes only couple of seconds. I just want this code to be working properly, no need for an additional search option in it.

Press machine gives a different value for different positions in the field of stress. But all those different "f" values I get from it, I can use in the same C code that was mentioned in this topic. Sp the C code is universal, and the input "f" changes - regarding of which I am looking for an appropriate f0, n31, n32, n33 from the C code.

What do you think about using integers with a larger range, instead of doubles?
I do not understand you, but if that will solve the problem (I want "f0" output to be ranging from 1e-26 to 1e-5) than I have nothing against it, even though I do not know what is it about. Sorry for my ignorance.

8. Originally Posted by stgeorge
Still the most lower value for "f0" is around 1.2e-011.
Sorry but in my system it is 1e-26 :/ That's why i suggested that to you

9. Whilst a double can store any number between 1E-308 and 1E308 (a range of just over 600 digits), it only represents the most significant 15 digits with any accuracy.

An example is trying to do 1E10 + 1E-10. The two numbers are separated by 20 decimal places, but a double can only store 15 decimal places.
The result is still just 1E10 (not 1E10 and a very small fraction).

If the numbers you're combining are in the same general order of magnitude, then FP is pretty good.
If you've got widely different orders of magnitude, then you need to proceed with some care.

> for(f0=1.0e-26;f0<=1.0e-5;f0=f0*pow(10.0,0.02))
How much accumulated error is there going to be in this?

10. I am not sure I understood you Salem. Please forgive me for my ignorance.

Originally Posted by std10093
Sorry but in my system it is 1e-26 :/ That's why i suggested that to you
I do not know what to say std10093. I am definitively doing something wrong.
Here is the code edited the way you told me:

Code:
```#include<stdio.h>
#include<math.h>

int main(void){
float f0;
double n31,n32,n33,f;
double A=0.373;
printf("# f0, f, n31, n32,n33\n");
for(f0=1.0e-26;f0<=1.0e-5;f0=f0*pow(10.0,0.02)){
n31=-2.0+floor(1.29*pow(f0,-0.25));
n32=-2.0+floor(A*pow(f0,-0.25)*(12.0)*sqrt((n31+2.0)/(11.0*n31+43.0)));
n33=-2.0+floor(A*pow(f0,-0.25)*(41.5692)*sqrt((n31+2.0)/(11.0*n31+43.0)*(n32+2.0)/(11.0*n32+43.0)));
f=pow(13.5,1.5)*f0*pow(n31+2.0,-2.0)*pow(n32+2.0,-2.0)*(n33+2.0,-2.0);
printf("%g %g %i %i %i\n",f0,f,(int)n31,(int)n32,(int)n33);
}
}```
And here is the result:
http://img805.imageshack.us/img805/7711/98273657.jpg

I am still getting the value of around 1.2e-11 as the lowest one for "f0". Not "1e-26".
Is the solution maybe in that "pow(10.0,0.02))" Salem mentioned ?

11. It looks like a simple case of losing the scrollback history in your terminal. By default the Windows terminal only shows maybe 100 (or 300?) lines of scrollback, and anything older "falls off" and cannot be seen by scrolling up.

Any easy solution is to increase the scrollback history of the terminal to a much higher value. Another solution is to write the program output to a file which you can view later. This can be done by redirecting the standard output right on the command line:
Code:
`yourprogram.exe >numbers.txt`
(Obviously you can give your program and the text file different names as appropriate).

12. Code:
`f=pow(13.5,1.5)*f0*pow(n31+2.0,-2.0)*pow(n32+2.0,-2.0)*(n33+2.0,-2.0);`
You are probably missing a call to pow on that line, aren't you?
Code:
`f=pow(13.5,1.5)*f0*pow(n31+2.0,-2.0)*pow(n32+2.0,-2.0)*pow(n33+2.0,-2.0);`
Bye, Andreas

13. THANK YOU CHRISTOP !!!

It worked like a charm !!!
I right clicked on title bar of the Command prompt ->Properties -> Layout tab and increased the "Screen Buffer Size" from 300 to 1500. Now I can clearly see my "f0" ranging all the way from to 1e-26 to 1e-5!!!

Thank you once again, Christop !!!

I owe a beer to all of you!!!

EDIT:
Thank you Andreas!!!
That missing "pow" solved the thing about "f" being negative. Now everything is ok, "f" is always positive, as it should be.

14. Aha!

One correction on my post. If you need float ranges, they are in the float.h header file, limits.h is only for integral data types.