What does the dot mean? I have this formula: (k < 0.)
4 views (last 30 days)
Show older comments
Darius Vesa
on 28 Dec 2022
Commented: Darius Vesa
on 28 Dec 2022
Greeintgs,
I am trying to understand an algorithm made by someone else. In an S-Function at some line I have the following:
double k = 0;
....
k = input2[0] - input3[0];
....
else if ((input1[0] < parameter1[0]) && (k < 0.))
Every input and parameter in my S-Function is a 1 row element ( vector with 1 element ).
I know that putting a dot means that you manipulate the elements of a vector individually. The things that confuses me is: k isn't a vector with multiple elements.
If k isn't a vector with multiple elements. Is there any purpose of the element wise comparison?
0 Comments
Accepted Answer
Walter Roberson
on 28 Dec 2022
The code you are showing is C or C++ code, not matlab code. Any meaning matlab might give for dots is irrelevant; you have to look at what C or C++ do with the dots.
Anyhow it is simple. You are dealing with double precision numbers and 0. is the same thing as 0.0 which is a floating point zero.
In theory in C or C++ if k is double precision then
k < 0
with no dot means that you want to compare double precision k to (int) zero. Literal numeric constants in C and C++ default to integer if there is no decimal point in the literal.
So k<0 would in theory involve first loading an integer zero and then "widening" it to double precision zero before doing the comparison. Whereas since the source code does have the dot, k<0. involves loading a double precision zero directly and comparing that.
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!