473,563 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help please, strange behavior

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 #1
31 1640
Simply_Red wrote:
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 ;
What is the type of 'yhi', 'ylo', 'stepY'? What are their values?
What value do you get in 'nbNiveau'? What did you expect?

It is possible that you're encountering rounding (truncation in
case of integer division) and adding 1 doesn't do what you need
it to do.
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????
That last statement is beyond me. What do you mean by "the size of
ContNotOrd"? How the hell can you know the size? How can it be
different from the size you requested?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 14 '07 #2
On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Simply_Redwrote :
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 ;


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.
?
>
It is possible that you're encountering rounding (truncation in
case of integer division) and adding 1 doesn't do what you need
it to do.
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????
That last statement is beyond me. What do you mean by "the size of
ContNotOrd"? How the hell can you know the size? How can it be
different from the size you requested?

i just verify in watch window ContNotOrd[160].


Feb 14 '07 #3
Simply_Red wrote:
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;
[redacted]
In addition to what Victor said to you, the definitions above are C-ish
and not really needed. They should be:

struct Limites {
double Debut;
double Fin;
};

struct ElemTabCont {
double NivY;
bool Existe;
std::vector<Lim itesPtLimites;
};

No typedefs or "tag" names are necessary.
Feb 14 '07 #4
Simply_Red wrote:
On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>Simply_Redwrot e:
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 ;

>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.

Feb 14 '07 #5
Simply_Red wrote:
On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
>Simply_Redwrot e:
>>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
mutlipostin g:
>>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;
}ElemTabCon t;
>>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.
You have stumbled upon a well-known (now to you as well) situation
when 16/0.1 is not 160 (exactly) but rather 159.99999999999 9. Add
1 to it and you get 160.99999999999 9 and assign it to a 'long', you
get 160. It's called "imprecise representation of a decimal value"
and essentially all computers with binary FP units suffer from it.

To calculate those things "correctly" , add 1.0000001 instead of 1:

long nbNiveau = (yhi-ylo)/stepY + 1.0000001;

It's not pretty, but it will work better. The number of zeros after
the decimal point depends on your 'yhi-ylo' scale.
?
>>
It is possible that you're encountering rounding (truncation in
case of integer division) and adding 1 doesn't do what you need
it to do.
>>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??? ?
>That last statement is beyond me. What do you mean by "the size of
ContNotOrd"? How the hell can you know the size? How can it be
different from the size you requested?


i just verify in watch window ContNotOrd[160].
I don't know how you do that, but tell me, if you do

int main() {
long nbNiveau = 160;
char *ContNotOrd = new char[nbNiveau + 1];
}

and "verify in watch window", do you get 160 or 161 _elements_? Do
not tell me the last index (it is less by 1 than the size, right?)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 14 '07 #6
On 14 fév, 14:29, Rolf Magnus <ramag...@t-online.dewrote:
Simply_Red wrote:
On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Simply_Redwrote :
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 ;
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.....

Feb 14 '07 #7
Simply_Red wrote:
On 14 fév, 14:29, Rolf Magnus <ramag...@t-online.dewrote:
>Simply_Red wrote:
>>On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Simply_Redwr ote:
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
mutlipostin g:
>>>>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;
}ElemTabCon t;
>>>>void myfunc( )
{
.....
ElemTabCo nt * 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.....
Yes... And?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Feb 14 '07 #8
Simply_Red wrote:
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:
How did you tell? Probably you misinterpret some output that we do not see
because your code snippet is incomplete.
and even if i put: ContNonOrd = new ElemTabCont [nbNiveau+1]; the size of
ContNonOrd = nbNiveau????
Again, how did you tell?
Please post a minimal complete program that shows the problem. With the code
fragments from above, there is no way to tell what the problem is
(especially since we do not even know the types of yhi, yhl, and stepY.
Best

Kai-Uwe Bux
Feb 14 '07 #9
On 14 fév, 14:35, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Simply_Red wrote:
On 14 fév, 14:12, "Victor Bazarov" <v.Abaza...@com Acast.netwrote:
Simply_Redwrote :
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 ;
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.

You have stumbled upon a well-known (now to you as well) situation
when 16/0.1 is not 160 (exactly) but rather 159.99999999999 9. Add
1 to it and you get 160.99999999999 9 and assign it to a 'long', you
get 160. It's called "imprecise representation of a decimal value"
and essentially all computers with binary FP units suffer from it.

To calculate those things "correctly" , add 1.0000001 instead of 1:

long nbNiveau = (yhi-ylo)/stepY + 1.0000001;

It's not pretty, but it will work better. The number of zeros after
the decimal point depends on your 'yhi-ylo' scale.
?
It is possible that you're encountering rounding (truncation in
case of integer division) and adding 1 doesn't do what you need
it to do.
>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????
That last statement is beyond me. What do you mean by "the size of
ContNotOrd"? How the hell can you know the size? How can it be
different from the size you requested?
i just verify in watch window ContNotOrd[160].

I don't know how you do that, but tell me, if you do

int main() {
long nbNiveau = 160;
char *ContNotOrd = new char[nbNiveau + 1];
}

and "verify in watch window", do you get 160 or 161 _elements_? Do
not tell me the last index (it is less by 1 than the size, right?)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
when i give a value to ContNotOrd[161] i have a crash, and 160
no.....for my example i check the vector of the 160 elem, when there
is no pb it contain _First = 0 _Last = 0 _End = 0.

Feb 14 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1455
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...
3
1707
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>
87
9521
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>
3
1708
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...
5
1554
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;
10
1745
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) {
2
1353
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...
12
20632
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...
3
2616
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:
0
7659
marktang
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...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7634
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...
1
5481
isladogs
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...
0
5208
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...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
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
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.