Discussion of the possibility of conflicting information on some pages on the documentation - page 2

 

people can't wrap their head around the word integer because the poor code example uses double. 

What code example are you referring to?, there is no example on the MathRound() doc page. 

There is a description of the function, no example code.

Did you bother to read the quote that I posted about functions?

Why have you not replied to my earlier post?

   //In main code
   Print("test=",test() );  

 

//function
double test()
 {
 int a=10;
 return(a);
 }

  Do you expect the test function to return an integer 10 or a double 10.0 ?

 Please give the reason for your answer (preferably in less than 20 words) 

 
JD4:

I am not assuming anything.  I am expecting a programming language documentation page to do it's job properly, be the documentation page for a specific piece of the programming language, and accurately document the code it is for.  As I said, this is a discussion about the code, not a concept.  Concepts are fine within programming in discussions on how to get something done.  We are discussing the specifics of the page, not a concept about the page or a concept about something on the page.


ydrol:

The page does not say that anywhere. You know it , we all know it.  The document clearly says the return type is double. (via prototype), and the return value is "Value rounded till to the nearest integer. "  is the mathematical definition of integer. It's simple.

Except for the fact that it doesn't.  It says integer.  Twice.  Once at the top, and once on the page in the area specifically marked return type.  It doesn't say double in the area marked return type, it doesn't say prototype there either, it says "integer."  I have posted it so many times, as have many others, not going to post it yet again because people can't wrap their head around the word integer because the poor code example uses double.  The only place it "says" double is in the code example.  The examples are supposed to demonstrate proper use and support the rest of the page, not brow beat the rest of the page into saying something different.

There is no example on that page. Example code is preceded by the word "Example:" and is code that shows an example of the function being used. Have a look at some of the other functions in the documentation.

The data type that functions return isn't always stated in the description but is always shown in the function prototype(s). Here the documentation just says that the function returns a "value" and states how it is calculated ("rounded to the nearest integer"). It nowhere states that it returns an int type. The keyword int doesn't appear anywhere on that page at all.

 
ydrol:

Last one for you... as you like C++ so much , I guess you have the same 'issues' with this page...

floor double floor (double x); Rounds x downward, returning the largest integral value that is not greater than x.

And on the same site...

is_integral  Trait class that identifies whether T is an integral type.

A C++ site happily using 'integral' mathematically in one context , and as a datatype in another. I suggest you pester them also.

Right must get back to my EA that will make me rich beyond my wildest dreams ... 


I used C++ only because MQL is (according to MQ via their documentation) based on it.  I do not program in C++, I have programmed in Java, and I am trying to learn to program in MQL as well.  Poorly written and/or inaccurate documentation makes that prospect that much harder.

Integral and integer are two different words with two different (but related) meanings in the cases you posted.  Int (or integer) is a specific data type, as is float or bool or char.  Integral is a broader definition, they call it a "fundamental data type."  In this respect, you could consider integral to be like an object class in programming, where the integer data type would be equivalent to a specific instance of that class.  Or to put it another way (within the scope of programming examples given above), an integer is integral, but an integral is not necessarily an integer.

On your floor function example, it says further down on the page (which I have posted before btw) the return value area states it returns a double.  Clearly written return type.  MQL's MathRound page does not because the coding example given shows double when the return area shows integer.  Not clearly written, as the page contains conflicting information.  So, that counter point fell flat.  Sorry.

Is_integral is clearly identified as a test of is this item a part of "a specific group."  Further down, there is a table that specifies the "fundamental integral types.".  And none of the examples in that table say anything about any data type that is not functionally defined as anything with fractional or decimal numbers.

Since the word integral has different meanings, and within programming, it is not a specific data type, and their documentation page is clearly written how they mean it (in both examples), that looks like counter point 2 fell down as well.  Sorry again.

Here is a counter-counter point, the doc page at C++ regarding variables, to which I think is very appropriate, since this is about programming, not concepts.  They have a table on there that has the types broken down into areas.  Clearly shows what they consider integers and what is not.  Well documented.  Perfect?  Probably not.  As I am not programming in C++, I am unlikely to see errors there.  Since I am trying to learn MQL, I am much more likely to notice errors in the documentation for that language.  Were I working on C++ programs, and saw an error, I would bring it to the attention of the people in charge of the documentation.

But since you want to bring concepts into it, here is my take on them.  Programming can use concepts to explain something, and there is nothing wrong with that, when it is used properly.  Variable is a concept, but you can't use the concept alone to program.  You have to use specific variables, with specific names, and specific data types.  The idea of a constant is a concept, and that is fine, but you have to specify which items are constants.  You can't program just using the concept.  Even within int, you can explain it as a concept, because it defines the idea of what something is supposed to be, but context is everything.  If you are using integer in the place marked what type you are returning from a function, and it is supposed to say double, then that concept is not the correct one to convey.

 

You are right, the function doesn't have to cast, but the example does because the doc page states integer, not double, in the return type.

 JD4 here's the problem: And you might just reply with 300 words, but I think its becoming more evident to all based on some of the things you have said:

-You dont have a clear understanding of what function prototypes are - and what they are used for (they are not poor code examples - they are definitions)

-You dont have a clear understanding of when(if) casting occurs in relation to function return types  (specifying a return type does not mean casting occurs).

-You cant handle the thought that Mathematical functions, beginning with the word 'Math', just  might just be talking about 'integer' as a mathematical concept (rather than a datatype). 

-You read the words 'Return Value' as 'Return Type' when it suits you . 

 
GumRai:

What code example are you referring to?, there is no example on the MathRound() doc page. 

There is a description of the function, no example code.

Did you bother to read the quote that I posted about functions?

Why have you not replied to my earlier post?

 

  Do you expect the test function to return an integer 10 or a double 10.0 ?

 Please give the reason for your answer (preferably in less than 20 words) 

 


double  MathRound(
   double  value      // value to be rounded
   );

Code example @euclid and Gum (and @ ydrol I think as well), this shows how to use the code by example, if you prefer code sample, I am apparently calling it a different name than you are, for that I am sorry.  It's purpose is the same.  It is supposed to show you how to use the code.

(already over 20 words Gum, it is how I am, sorry)

Sorry about not responding to your other post Gum, it was not intentional.  In talking about your "test" function, I would expect it to return a double because you are telling it to return a double, as the code repeated above does.

@ euclid, the not being stated there is part of my issue, it should be as it is supposed to document the code.

@ ydrol, my mind knows what I mean and my hands do not always cooperate.  So I am probably meaning one thing and not saying it how it is in my head.  Sorry.  Casting is supposed to mean changing the type of an item to another before storing in a variable of a different type.  I used that word improperly.  The way I was using it was not as proper as I intended.  You are telling, with the double word (or whatever), that you want the function to return a double.  Math functions as concepts are fine, as I showed in my last post.  As I also showed, there is a proper usage to them.

I used Return Value and Return Type because they were used on the examples I quoted.  I do not try to change how they are used.

Now, for my take on this.  The documentation is not clear, maybe because it uses the "concept" of integer within the "Return Value" here, and in other languages' doc pages, they use "Return Type."  It still stands that it should be stating that, because integer is a valid data type, not just a concept, that it returns a double data type, even within the area marked Value.  If it clearly stated that it returns an integer value within a double type, it would be 100% clear to everyone (well, everyone that speaks and reads English hopefully).

 

  

In talking about your "test" function, I would expect it to return a double because you are telling it to return a double, as the code repeated above does.

That is precisely the point that we have been making. The return type for the function is a double, so it must return a double.

double  MathRound(
   double  value      // value to be rounded
   );

 This is not an example of coding, it is a description of what the function does

double

 tells you that whatever value you input between the (), the function MUST return a double

MathRound(
   double  value      // value to be rounded
   );

 tells you what it works on

The following text explains what the function does

Parameters

value

[in]  Numeric value before rounding.

Return Value

Value rounded till to the nearest integer.

Not what type it returns. That has already been described.

As you have been told many time, it is not meant to be an example. Try pasting it into your code and see if it works. It won't !

THIS is an example

   double source = 5.55;  
   double result = MathRound(source);
 
Hello guys, I do not have time to read the entire thread, but I wonder if all the discussion is about the double<->integer implicit conversion.
JD4:

I used C++ only because MQL is (according to MQ via their documentation) based on it.  I do not program in C++, I have programmed in Java, ...

Integral and integer are two different words with two different (but related) meanings ...


I am not sure if it could help you, but Java uses a term "primitive" rather than "integral". It has no relation to an integer. "Casting" (both explicit and implicit) of primitive types is rather a conversion than a change of a type declaration (it changes not only the type, but also its memory representation, i.e. it becomes another variable). Good luck in further discussion.
 
Ovo:
Hello guys, I do not have time to read the entire thread, but I wonder if all the discussion is about the double<->integer implicit conversion.

 The discussion is a semantic one about whether

double  MathRound(
   double  value      // value to be rounded
   );

 should return a double or an integer.

*cough* double *cough* 

 
honest_knave:

 The discussion is a semantic one about whether

double  MathRound(
   double  value      // value to be rounded
   );

 should return a double or an integer.

*cough* double *cough* 

 

 

Because integer is used twice elsewhere on the page, including the one where it shows the return value.  Should show the whole cause.  There was no debate if a statement just showing

double  MathRound(
   double  value      // value to be rounded
   );

should return a double as it is being told to.  But if it is in fact supposed to when the 2 other places on the doc page says it returns an integer, THAT is the issue.

 
GumRai:

  

That is precisely the point that we have been making. The return type for the function is a double, so it must return a double.

 This is not an example of coding, it is a description of what the function does

 tells you that whatever value you input between the (), the function MUST return a double

 tells you what it works on

The following text explains what the function does

Not what type it returns. That has already been described.

As you have been told many time, it is not meant to be an example. Try pasting it into your code and see if it works. It won't !

THIS is an example

 

double source = 5.55;  

double result = MathRound(source);

 

Correct, it is an example.  An example of how to call the function, not how to use the code as you would as one piece to build the program.  When I used the print function example before, the code that I used was in error because I was doing the same thing.  I was not showing the way the print function was coded, as was my intent.  And as I said, elsewhere on the page it says returns an integer, but the function doesn't.  Which brings up my point, either the code of the function (and the place that shows the code, which I have been calling an example), or the doc page is broken and one or the other needs to be fixed.
Reason: