i'm sorry i posted this in other groupes, and i didn't see it, and as
this group is most actif, i repost it here, and sorry for
mutliposting:
Hi,
i'm using VC6, i have this declaration:
typedef struct tagTLimite {
double Debut;
double Fin;
}Limites;
typedef struct TagElemTab {
double NivY;
bool Existe;
std::vector<Lim itesPtLimites;
}ElemTabCont;
void myfunc( )
{
......
ElemTabCont * ContNonOrd;//contour non ordone
long nbNiveau = (yhi-ylo)/stepY +1 ;
ContNonOrd = new ElemTabCont [nbNiveau];
......
}
i don't know why,nbNiveau is equal to (yhi-ylo)/stepY, it didn't
+1????and even if i put:
ContNonOrd = new ElemTabCont [nbNiveau+1]; the size of ContNonOrd =
nbNiveau????
Feb 14 '07
31 1665
"Simply_Red " <Si**********@g mail.comwrote in message
news:11******** **************@ s48g2000cws.goo glegroups.com.. .
typedef struct tagTLimite {
double Debut;
double Fin;
}Limites;
typedef struct TagElemTab {
double NivY;
bool Existe;
std::vector<Lim itesPtLimites;
}ElemTabCont;
void myfunc( )
{
.....
ElemTabCont * ContNonOrd;//contour non ordone
long nbNiveau = (yhi-ylo)/stepY +1 ;
>What is the type of 'yhi', 'ylo', 'stepY'? What are their values? What value do you get in 'nbNiveau'? What did you expect
yhi, ylo, stepY are doubles values: 16, 0, 0.1 respectively
I get 160 in nbNiveau, and I need 161.
double isn't precise either. Note that 0.1 in binary is a periodic number that cannot be represented exactly. So instead of 0.1, you get the closest representabl e value. As a result, you might get something like 160.9999999999 8, which gets truncated to 160 when converted to long.
but if 160.999999998 is truncated to 160, 159.99999998 must be truncated to 159.....
True, but where did you get 159.99999998?
The problem is that, sometimes, the result of (yhi-ylo)/stepY will not be an
exact integer, because stepY may not be exactly representable in binary (as
a double or float). So sometimes your array size will be too small.
The solution for handling this depends on your goal. How are you later
using the array elements?
In your example, stepY is 0.1, or 1/10, which means you're expecting to get
(yhi-ylo)*10 = 160, right? Well, where does stepY come from? Can you
compute it from something like 1/numElementsPerU nit, where
numElementsPerU nit is an integer? If so, your code could change to:
nbNiveau = (yhi-ylo)*numElement sPerUnit + 1;
stepY = 1 / numElementsPerU nit;
That would avoid the issue entirely.
If stepY is not representable that way, and if yhi-ylo isn't too big, you
could just add 1.1 instead of 1 before truncating to an integer, but that's
not the prefered solution.
Victor's idea of "bumping up" the value might work for you, as well, if all
you care about is having "enough" elements in the array.
One thing to note: If you ever make calculations like (i-ylo)/stepY, or
simply i*stepY, then for large values of i the result will get further and
further from what you expect. But that's probably not be a problem for you,
since your values are small.
By the way, one thing I like to do when investigating problems involving
calculations like this is to store intermediate results to another variable,
like this:
double temp = (yhi-ylo)/stepY +1;
long nbNiveau = temp;
This lets you examine the values yourself when debugging, instead of trying
to guess what's going on inside the program.
Hope this helps...
-Howard
On 15 fév, 16:33, "Howard" <m...@here.comw rote:
"Simply_Red " <Simply.Re...@g mail.comwrote in message
news:11******** **************@ s48g2000cws.goo glegroups.com.. .
typedef struct tagTLimite {
double Debut;
double Fin;
}Limites;
typedef struct TagElemTab {
double NivY;
bool Existe;
std::vector<Lim itesPtLimites;
}ElemTabCont;
void myfunc( )
{
.....
ElemTabCont * ContNonOrd;//contour non ordone
long nbNiveau = (yhi-ylo)/stepY +1 ;
What is the type of 'yhi', 'ylo', 'stepY'? What are their values?
What value do you get in 'nbNiveau'? What did you expect
yhi, ylo, stepY are doubles values: 16, 0, 0.1 respectively
I get 160 in nbNiveau, and I need 161.
double isn't precise either. Note that 0.1 in binary is a periodic number
that cannot be represented exactly. So instead of 0.1, you get the
closest
representable value. As a result, you might get something like
160.99999999998 , which gets truncated to 160 when converted to long.
but if 160.999999998 is truncated to 160, 159.99999998 must be
truncated to 159.....
True, but where did you get 159.99999998?
The problem is that, sometimes, the result of (yhi-ylo)/stepY will not bean
exact integer, because stepY may not be exactly representable in binary (as
a double or float). So sometimes your array size will be too small.
The solution for handling this depends on your goal. How are you later
using the array elements?
In your example, stepY is 0.1, or 1/10, which means you're expecting to get
(yhi-ylo)*10 = 160, right? Well, where does stepY come from? Can you
compute it from something like 1/numElementsPerU nit, where
I take the value of stepY from a database, i can't compute it.
numElementsPerU nit is an integer? If so, your code could change to:
nbNiveau = (yhi-ylo)*numElement sPerUnit + 1;
stepY = 1 / numElementsPerU nit;
That would avoid the issue entirely.
If stepY is not representable that way, and if yhi-ylo isn't too big, you
could just add 1.1 instead of 1 before truncating to an integer, but that's
not the prefered solution.
Victor's idea of "bumping up" the value might work for you, as well, if all
you care about is having "enough" elements in the array.
One thing to note: If you ever make calculations like (i-ylo)/stepY, or
simply i*stepY, then for large values of i the result will get further and
further from what you expect. But that's probably not be a problem for you,
since your values are small.
By the way, one thing I like to do when investigating problems involving
calculations like this is to store intermediate results to another variable,
like this:
double temp = (yhi-ylo)/stepY +1;
long nbNiveau = temp;
This lets you examine the values yourself when debugging, instead of trying
to guess what's going on inside the program.
Hope this helps...
-Howard
thank you for your help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Steven |
last post by:
Hi all
My problem is a little lengthy. But please help me. In my application,
ADO.NET DataSet object is not getting constructed in the Web Service Web
Method called by the Windows Application passing an ADO.NET DataSet Object
as a parameter to the Web Method in Web Service
Debugging using the Soap Extensions, clearly shows that the Serialized
DataSet is passed to the Web Service, but the Web Service Web Method is not
|
by: John |
last post by:
I am new to c++ programming and i just want to make a program that
takes a users name, then converts it to a hex string, then puts it
together in a fixed order.
An example output would be:
Name: John
Output: 84721305
this is my generation code so far
#include <conio.h>
|
by: expertware |
last post by:
Dear friends,
My name is Pamela, I know little about CSS,
but I would like to ask a question
I have an image on a web page within a css layer:
<DIV ID=MyLayer
STYLE = "position: absolute;top:68px; left:563px;
width:640px;height:480px;">
<IMG src="ReportImageBox_12.54.52.png" width=640 height=480></IMG>
|
by: Mitchell Thomas |
last post by:
I hope someone out there can solve my mysterious problem. I have
tried everything imaginable, even paid $35 to Microsoft to help me,
but they were not able to figure out this problem: Here is the
problem:
I recently created a new database in Access 2002. I took data from an
> access 97 database converted one of the tables to access 2002 and then
> imported it into a new table in access 2002. but for some strange
> reason, every once...
|
by: cpptutor2000 |
last post by:
I am compiling and running the following code snippet on a Linux box -
I am really
puzzled by the answers. Could someone please tell me what might be
wrong?
void test(){
int m = 0;
int n = 0;
int i = 0;
int j = 0;
| |
by: weichaoliu |
last post by:
I know that this problem is concerned to GCC. But I hope somebody here
can tell me some detailed things about why.
The version of g++ I'm using is: g++ (GCC) 3.4.4 (mingw special).
The code is:
// BEGIN
#include<iostream>
int main(void)
{
|
by: Webdiyer |
last post by:
Hi,
We all know that the return value of Math.Log(8,2) is 3,but how about
(int)Math.Log(8,2)? On my machine,the return value of (int)Math.Log(8,2) is
strange enough! it's not 3 but 2 ! I've tested other values such as
(int)Math.Log(16,2),(int)Math.Log(4,2),(int)Math.Log(32,2)...et, they all
return the same value as their counterpart Math.Log() methods,only
(int)Math.Log(8,2) is incorrect,is this a .net bug ? I've also tested...
|
by: John |
last post by:
I can't get my head around this!
I have the following code:
<%
.... Code for connection to the database ...
.... Code for retrieving recordset ...
If Not rs.EOF Then
... Do something...
|
by: Chuck Renner |
last post by:
Please help!
This MIGHT even be a bug in PHP!
I'll provide version numbers and site specific information (browser, OS,
and kernel versions) if others cannot reproduce this problem.
I'm running into some PHP behavior that I do not understand in PHP 5.1.2.
I need to parse the HTML from the following carefully constructed URI:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |