Mixed 2D array (or vector,list,etc.): integer and double
-
Sone: If the results are the same, they come earlier and the source is cleaner, I wouldn't care for SeppJ's remarks about semantics, even if I were a long time reader of this forum.
Anyways, I feel there's no good generic solution we can propose without any restrictions on the data layout given.
-
Decimad schrieb:
Sone: If the results are the same, they come earlier and the source is cleaner, I wouldn't care for SeppJ's remarks about semantics, even if I were a long time reader of this forum.
The point is, if you change the semantics you change the result. If 4sambo had any valid reason for using integers for some numbers instead of doubles for everything, you cannot just tell him to use doubles instead.
-
you should use variant or any on the level of the rows (as you know that every element of the row has the samee typ) instad on the level of elements. alternatively you could create two arrays: one storing the double lines and the other storing the integer. of course you would need to store which line is what...so maybe you should use any instead.
-
Use 2 tables: one for your integers and one for your doubles.
-
@4sambo: As you can see, you get 10 answers and 10 different, incompatible opinions on the best solution. The reason is, that we do not know which problem you want to solve, only what you think the best solution would be. If you actually explained why you need this mixed table we might propose a better solution (or the same solution with a precise way of implementing it). There are several regular readers who do computer simulations themselves and the mathematicians and computer scientists are also pretty good at modelling and finding algorithms
.
-
@SeppJ and all the others: Thank you very much again.
Yes all of you mentioned a lot of different and useful ideas.
May to focus my problem, it is important for me to use integers and doubles due to memory size.
Additionally I always have rounding problems with c++ when I am trying to convert a double to integer: Sometimes c++ saves a real number e.g. 2 as 1.9999999999 or 2.000000001 which leads to 2 (which is right) or 1 when converting it to an integer. But this is an other problem. By the way based on the integer value I am defining my grid point.So the actual reason why I need it is that I want to generate a quadtree (2-D) or octree (3-D) grid. So for every element(=grid point) I have to save some solution values (approx 24 doubles) and some definition (approx 10 integers)
-
4sane schrieb:
Additionally I always have rounding problems with c++ when I am trying to convert a double to integer: Sometimes c++ saves a real number e.g. 2 as 1.9999999999 or 2.000000001 which leads to 2 (which is right) or 1 when converting it to an integer. But this is an other problem. By the way based on the integer value I am defining my grid point.
Integer values should all be representable exactly in any common floating point implementation (actually there is only one that is common and everbody uses it). Of course, this may not be the case if the integer is the result of some real valued computation. In that case you should use some kind of rounding instead of direct assignment or a cast. The standard library offers many different functions: ceil, floor, trunc, round, nearbyint, rint and several variations of these. So you do not even need to think about rounding schemes (just look at the different options) and their implementation.
So the actual reason why I need it is that I want to generate a quadtree (2-D) or octree (3-D) grid. So for every element(=grid point) I have to save some solution values (approx 24 doubles) and some definition (approx 10 integers)
I must admit, I know alomost nothing about quadtrees, can't help you there.
-
4sane schrieb:
So the actual reason why I need it is that I want to generate a quadtree (2-D) or octree (3-D) grid. So for every element(=grid point) I have to save some solution values (approx 24 doubles) and some definition (approx 10 integers)
For what? i implemented some binary space partition trees and i never neded that. So for what do you ned the integers and what should be the solution values?
Neverthelss: i have the feeling that double and itneger values have quite a different semantic and you should not store them in the same data structure.
-
4sane schrieb:
So the actual reason why I need it is that I want to generate a quadtree (2-D) or octree (3-D) grid. So for every element(=grid point) I have to save some solution values (approx 24 doubles) and some definition (approx 10 integers)
struct values { double d[24]; int i[10]; };
-
@otze: I need integer to store the kind of element (obstacle, fluid element, inlet, etc.) and the double are necessary to store the results like density, velocity vector, etc. The basic idea is to use the quadree/octree method to refine my mesh close to obstacles. http://www.zeusnumerix.com/public/images/gallery/zn25533230142747625295img.png
I think the best idea is to seperate my array into an two. One for storing the integer element and the other for the doubles.