Skip to content

Commit

Permalink
add more getMinVersionFromData handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
adriweb committed Jul 16, 2024
1 parent e3a718e commit a4e73e3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 8 deletions.
Binary file modified TIVarsLib.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions src/TypeHandlers/STH_ExactFraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace tivars::TypeHandlers

uint8_t STH_ExactFraction::getMinVersionFromData(const data_t& data)
{
// handled in TH_GenericXXX
(void)data;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/TypeHandlers/STH_ExactFractionPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace tivars::TypeHandlers

uint8_t STH_ExactFractionPi::getMinVersionFromData(const data_t& data)
{
// handled in TH_GenericXXX
(void)data;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/TypeHandlers/STH_ExactPi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace tivars::TypeHandlers

uint8_t STH_ExactPi::getMinVersionFromData(const data_t& data)
{
// handled in TH_GenericXXX
(void)data;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/TypeHandlers/STH_ExactRadical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace tivars::TypeHandlers

uint8_t STH_ExactRadical::getMinVersionFromData(const data_t& data)
{
// handled in TH_GenericXXX
(void)data;
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/TypeHandlers/STH_FP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ namespace tivars::TypeHandlers

uint8_t STH_FP::getMinVersionFromData(const data_t& data)
{
// handled in TH_GenericXXX
(void)data;
return 0;
}
Expand Down
10 changes: 8 additions & 2 deletions src/TypeHandlers/TH_GenericComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ namespace tivars::TypeHandlers

uint8_t TH_GenericComplex::getMinVersionFromData(const data_t& data)
{
(void)data;
return 0;
const uint8_t internalType = (uint8_t)(data[0] & 0x3F);
if (internalType == 0x0C) { // Complex
return 0x00;
} else if (internalType == 0x1B) { // Fraction
return 0x0B;
} else {
return 0x10;
}
}
}
15 changes: 13 additions & 2 deletions src/TypeHandlers/TH_GenericList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,18 @@ namespace tivars::TypeHandlers

uint8_t TH_GenericList::getMinVersionFromData(const data_t& data)
{
(void)data;
return 0;
uint8_t version = 0;
for (size_t offset = 2; offset < data.size(); offset += 9) {
uint8_t internalType = data[offset] & 0x3F;
if (internalType > 0x1B) { // exact complex frac
version = 0x10;
break;
} else if (internalType == 0x1B) { // exact complex frac
if (version < 0x0B) version = 0x0B;
} else if (internalType == 0x18 || internalType == 0x19) { // real/mixed frac
if (version < 0x06) version = 0x06;
}
}
return version;
}
}
4 changes: 2 additions & 2 deletions src/TypeHandlers/TH_GenericReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace tivars::TypeHandlers

uint8_t TH_GenericReal::getMinVersionFromData(const data_t& data)
{
(void)data;
return 0;
const uint8_t internalType = (uint8_t)(data[0] & 0x3F);
return (internalType == 0) ? 0x00 : 0x06;
}
}
15 changes: 13 additions & 2 deletions src/TypeHandlers/TH_Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,19 @@ namespace tivars::TypeHandlers

uint8_t TH_Matrix::getMinVersionFromData(const data_t& data)
{
(void)data;
return 0;
uint8_t version = 0;
for (size_t offset = 2; offset < data.size(); offset += 9) {
uint8_t internalType = data[offset] & 0x3F;
if (internalType > 0x1B) { // exact complex frac
version = 0x10;
break;
} else if (internalType == 0x1B) { // exact complex frac
if (version < 0x0B) version = 0x0B;
} else if (internalType == 0x18 || internalType == 0x19) { // real/mixed frac
if (version < 0x06) version = 0x06;
}
}
return version;
}

}

0 comments on commit a4e73e3

Please sign in to comment.