Hello again,
As previously mentioned, I'm trying to build an extensible and data type agnostic extension to the CSV functionality. This is a follow up post about the issues I've encountered with primitive assignment and very slow decimal transformation, hence these examples are combined in a single post.
1) The following line causes dnc to block or to be very slow. Code:2) The following lines cause a seg fault. Why? If you substitute the 10 for a 3 it blocks, or is very slow. I suspect Dana uses the array size in the RHS of the assignment, but why does this not throw a meaningful error. Code: dec64 newColumn[] = new dec64[](1.2, 2.3, 3.4)
out.print("newColumn[0] = $(newColumn[0]), newColumn[1] = $(newColumn[1]), newColumn[2] = $(newColumn[2])\n")
int16 newColumn[] = new int16[](22239572, 2123561343, 13513451334)
byte serialData[] = clone dana.serial(newColumn)
3) The idea for the CSV extension is to be able to pass any data type to the function to be written to a CSV file. This means that I have to follow this pattern for primitive data types (i.e. int and dec):
// Why does this work for integers but not for decimals?
cue.addColumn("test.csv", true, ",", cue.wrapIntArray(new int512[](newIntColumn), 8),
columnName = "NewColumnInt8"/* , columnNumber = 3 */, limitData = false)
cue.addColumn("test.csv", true, ",", cue.wrapDecArray(new dec512[](newDecColumn), 8),
columnName = "NewColumnDec8"/* , columnNumber = 3 */, limitData = false)
Here the interesting part is the wrapIntArray and wrapDecArray functions which transform any size int and dec to int512 and dec512.
However, this only works for integers and not decimals as demonstrated by this. Code:
int16 int16Array[] = new int16[](1, 2, 3, 12, 43, 4433)
int512 int512Array[] = new int512[](int16Array)
for (int i = 0; i < int512Array.arrayLength; i++) {
out.print("int512Array[$(i)] = $(int512Array[i])\n")
}
dec decArray[] = new dec[](1.0, 43.2, -1.2)
dec512 dec512Array[] = new dec512[](decArray)
for (int i = 0; i < dec512Array.arrayLength; i++) {
out.print("dec512Array[$(i)] = $(dec512Array[i])\n")
}
The output from the above code is:
int512Array[0] = 1int512Array[1] = 2int512Array[2] = 3int512Array[3] = 12int512Array[4] = 43int512Array[5] = 4433dec512Array[0] = 11242005596642755118.6925521544392995069dec512Array[1] = -11912999616504406411.5172415816139032473dec512Array[2] = -3739427922542488922.3053478470991316394
4) The final problem could be demonstrated with this example:
int512 int512Array[] = new int512[](1023462456354735467567968894568467938, 1234, 5234562)
out.print("int512Array[0] - $(int512Array[0])\n")
int intArray[] = new int[](int512Array)
out.print("int512Array[0] - $(int512Array[0])\n")
out.print("intArray[0] - $(intArray[0])\n")
out.print("$(typeof(int512Array[0]).size) - size\n")
out.print("$(typeof(intArray[0]).size) - size\n")
Here the output is:Is the issue a printing one or is it something to do with the int512Util? Also is there adec512Util?From my experience the decimal results are somewhat random and take a lot to produce and print. int512Array[0] - 15700956033302498786
int512Array[0] - 15700956033302498786
intArray[0] - 15700956033302498786
512 - size
8 - size
5) Finally, how to convert dec to int and vice-versa? I.e., what is the general procedure?
Apologies for the long post.But this really obstructs the decimal feature of the CSV extension.
Many thanks,
Sava
