Skip to content

Commit

Permalink
Some improvements to SprintfDoubleSignifFigures() & FillWithZerosBefo…
Browse files Browse the repository at this point in the history
…reLoadingDoubleIntoMemory()
  • Loading branch information
AbelPau committed Apr 16, 2024
1 parent ac6a58f commit 80156f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
26 changes: 13 additions & 13 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2353,8 +2353,8 @@ static char *FillWithZerosBeforeLoadingDoubleIntoMemory(
#undef MAX_SIGNIFICANT_FIGURES
} // End of FillWithZerosBeforeLoadingDoubleIntoMemory()

int SprintfDoubleSignifFigures(char *szChain, size_t size_szChain,
int nSignifFigures, double nRealValue)
int MM_SprintfDoubleSignifFigures(char *szChain, size_t size_szChain,
int nSignifFigures, double dfRealValue)
{
double VALOR_LIMIT_PRINT_IN_FORMAT_E;
double VALOR_TOO_SMALL_TO_PRINT_f;
Expand All @@ -2378,13 +2378,13 @@ int SprintfDoubleSignifFigures(char *szChain, size_t size_szChain,

memset(szChain, '\0', size_szChain);

if (MM_IsNANDouble(nRealValue))
if (MM_IsNANDouble(dfRealValue))
return snprintf(szChain, size_szChain, "NAN");

if (MM_IsDoubleInfinite(nRealValue))
if (MM_IsDoubleInfinite(dfRealValue))
return snprintf(szChain, size_szChain, "INF");

if (!nRealValue)
if (!dfRealValue)
return snprintf(szChain, size_szChain, "%.*f", nSignifFigures, 0.0);

if (nSignifFigures < 1)
Expand All @@ -2393,28 +2393,28 @@ int SprintfDoubleSignifFigures(char *szChain, size_t size_szChain,
if (nSignifFigures > N_POWERS)
nSignifFigures = N_POWERS;

retorn =
snprintf(szChain, size_szChain, "%.*E", nSignifFigures - 1, nRealValue);
retorn = snprintf(szChain, size_szChain, "%.*E", nSignifFigures - 1,
dfRealValue);

VALOR_LIMIT_PRINT_IN_FORMAT_E = potencies_de_10[nSignifFigures - 1];
VALOR_TOO_SMALL_TO_PRINT_f =
fraccions_de_10[MM_MAX_XS_DOUBLE - nSignifFigures];

if (nRealValue > VALOR_LIMIT_PRINT_IN_FORMAT_E ||
nRealValue < -VALOR_LIMIT_PRINT_IN_FORMAT_E ||
(nRealValue < VALOR_TOO_SMALL_TO_PRINT_f &&
nRealValue > -VALOR_TOO_SMALL_TO_PRINT_f))
if (dfRealValue > VALOR_LIMIT_PRINT_IN_FORMAT_E ||
dfRealValue < -VALOR_LIMIT_PRINT_IN_FORMAT_E ||
(dfRealValue < VALOR_TOO_SMALL_TO_PRINT_f &&
dfRealValue > -VALOR_TOO_SMALL_TO_PRINT_f))
return retorn;

ptr = strchr(szChain, 'E');
if (!ptr)
return 0;
exponent = atoi(ptr + 1);

nRealValue = atof(FillWithZerosBeforeLoadingDoubleIntoMemory(
dfRealValue = CPLAtof(FillWithZerosBeforeLoadingDoubleIntoMemory(
szChain_retorn, MM_CHARACTERS_DOUBLE + 1, szChain));
return sprintf(szChain, "%.*f", max(0, nSignifFigures - exponent - 1),
nRealValue);
dfRealValue);
#undef N_POWERS
} // End of SprintfDoubleXifSignif()

Expand Down
8 changes: 4 additions & 4 deletions ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,8 +2270,8 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
return OGRERR_NOT_ENOUGH_MEMORY;

char szChain[21];
SprintfDoubleSignifFigures(
szChain, 21,
MM_SprintfDoubleSignifFigures(
szChain, sizeof(szChain),
phMiraMonLayer->pLayerDB->pFields[iField].nNumberOfDecimals,
padfRLValues[nIRecord]);

Expand Down Expand Up @@ -2424,8 +2424,8 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
return OGRERR_NOT_ENOUGH_MEMORY;

char szChain[21];
SprintfDoubleSignifFigures(
szChain, 21,
MM_SprintfDoubleSignifFigures(
szChain, sizeof(szChain),
phMiraMonLayer->pLayerDB->pFields[iField].nNumberOfDecimals,
poFeature->GetFieldAsDouble(iField));

Expand Down

0 comments on commit 80156f2

Please sign in to comment.