The outcome of both is zero. I think that is the correct answer. I stared for a long time at both pieces of code, but the difference does not show, no matter how long I stare at it Sorry, they are different, see post #7
I don't see "Float" anywhere in the code.
If "Float" is somewhere defined in your Arduino code or libraries, then something is very wrong
Your topic has been moved to a more suitable location on the forum. Please see the sticky topics in Uncategorized - Arduino Forum why you should not post in Uncategorized.
I think you are right, there must be a function or macro that makes the "Float". I have been searching, but there is no "Float" in C or C++ or std or Arduino.
Everyone is getting sidetracked by the capitalization of "Float()" in the title. This is actually not the fault of @jesse_a_b, but rather the result of the forum software's behavior of automatically capitalizing the first letter of the title if the topic creator did not do so.
If you look at the actual code posted, you can see the difference is this:
(note it is float with a lower case f)
vs. this:
So it is only about a standard type cast. No mysterious function involved.
These are two different type cast syntaxes. The float(foo) syntax is referred to as "functional" notation. The (float)foo syntax is referred to as "c-like" notation.
The two should be functionally identical in this application. I believe this is the relevant part of the C++11 specification:
the type conversion expression is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression ([expr.cast]).
So I don't have any explanation about why you would get a "completely wrong" value from one and not the other. As already explained, we would need more information to investigate that.
My personal preference is for the "c-like" notation. The reason is that you can't use the functional notation in all applications. For example, you can do this:
I meant that jesse_a_b might have a bug in the sketch and I created such a thing to cause a difference in the outcome.
I hope that you agree that the sketch that I wrote is very ugly !
that's why we usually ask for a minimum example code that will compile and show the issue at hand... with the Snippets shared by @jesse_a_b it is impossible to tell what's the issue as it's very likely not his real code.
The function float() is not defined and yet the compiler does not report any error message. It is due to the fact that float is a keyword which is known to the compiler.
The compiler has failed to account that a keyword cannot be used as a function name.
OP wants that the integer content (200) of NSamples variable is to be converted into a floating point number (200.0) by a process what is called casting and accordingly he has appended (float) before the variable (for example: float y = (float)NSamples;).
Your example works correctly if you put a proper Serial.begin() into it, it has already been explained that the float() is a proper cast and not an undeclared function.
My simple understanding is:
Given: int y = float(byte a, byte b);
Assuming a new learner of programming language (like the OP) who has not much exposure to C++ Language Specifications including the keywords but has some knowledge about identifiers, I think he will consider that float is an identifier and will immediately accept float() as a function call. I have seen pupils to say that for(); is a function call as they don't know that for is a keyword which can not be used as an identifier.
In the present thread, the OP has no knowledge of the syntax of casting. He has written float(NSamples); instead of (float)NSamples;. I have expected that the compiler will report a warning/error; but, it has not done that. Anyway, you have explained the reason in post #15.