"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/converter.c" between
udunits-2.2.26.tar.gz and udunits-2.2.28.tar.gz

About: UDUNITS supports units of physical quantities. Its C library provides for arithmetic manipulation of units and for conversion of numeric values between compatible units.

converter.c  (udunits-2.2.26):converter.c  (udunits-2.2.28)
/* /*
* Copyright 2013 University Corporation for Atmospheric Research * Copyright 2020 University Corporation for Atmospheric Research
* *
* This file is part of the UDUNITS-2 package. See the file COPYRIGHT * This file is part of the UDUNITS-2 package. See the file COPYRIGHT
* in the top-level source-directory of the package for copying and * in the top-level source-directory of the package for copying and
* redistribution conditions. * redistribution conditions.
*/ */
/* /*
* Value converters for the udunits(3) library. * Value converters for the udunits(3) library.
*/ */
/*LINTLIBRARY*/ /*LINTLIBRARY*/
#ifndef _XOPEN_SOURCE #include "config.h"
# define _XOPEN_SOURCE 500
#endif #include "udunits2.h" // Accommodates Windows & includes "converter.h"
#ifdef _MSC_VER
#define _USE_MATH_DEFINES
#include "udunits2.h" /* For the MSVC-specific defines. */
#endif
#include <math.h> #include <math.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "converter.h" /* this module's API */
typedef struct { typedef struct {
cv_converter* (*clone)(cv_converter*); cv_converter* (*clone)(cv_converter*);
double (*convertDouble) double (*convertDouble)
(const cv_converter*, double); (const cv_converter*, double);
float* (*convertFloats) float* (*convertFloats)
(const cv_converter*, const float*, size_t, float*); (const cv_converter*, const float*, size_t, float*);
double* (*convertDoubles) double* (*convertDoubles)
(const cv_converter*, const double*, size_t, double*); (const cv_converter*, const double*, size_t, double*);
int (*getExpression) int (*getExpression)
skipping to change at line 934 skipping to change at line 928
cv_converter* cv_converter*
cv_get_scale( cv_get_scale(
const double slope) const double slope)
{ {
cv_converter* conv; cv_converter* conv;
if (slope == 1) { if (slope == 1) {
conv = &trivialConverter; conv = &trivialConverter;
} }
else { else {
conv = malloc(sizeof(ScaleConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->ops = &scaleOps; conv->ops = &scaleOps;
conv->scale.value = slope; conv->scale.value = slope;
} }
} }
return conv; return conv;
} }
skipping to change at line 966 skipping to change at line 960
cv_converter* cv_converter*
cv_get_offset( cv_get_offset(
const double offset) const double offset)
{ {
cv_converter* conv; cv_converter* conv;
if (offset == 0) { if (offset == 0) {
conv = &trivialConverter; conv = &trivialConverter;
} }
else { else {
conv = malloc(sizeof(OffsetConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->ops = &offsetOps; conv->ops = &offsetOps;
conv->offset.value = offset; conv->offset.value = offset;
} }
} }
return conv; return conv;
} }
skipping to change at line 1003 skipping to change at line 997
{ {
cv_converter* conv; cv_converter* conv;
if (slope == 1) { if (slope == 1) {
conv = cv_get_offset(intercept); conv = cv_get_offset(intercept);
} }
else if (intercept == 0) { else if (intercept == 0) {
conv = cv_get_scale(slope); conv = cv_get_scale(slope);
} }
else { else {
conv = malloc(sizeof(GalileanConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->ops = &galileanOps; conv->ops = &galileanOps;
conv->galilean.slope = slope; conv->galilean.slope = slope;
conv->galilean.intercept = intercept; conv->galilean.intercept = intercept;
} }
} }
return conv; return conv;
} }
skipping to change at line 1038 skipping to change at line 1032
cv_converter* cv_converter*
cv_get_log( cv_get_log(
const double base) const double base)
{ {
cv_converter* conv; cv_converter* conv;
if (base <= 1) { if (base <= 1) {
conv = NULL; conv = NULL;
} }
else { else {
conv = malloc(sizeof(LogConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->ops = &logOps; conv->ops = &logOps;
conv->log.logE = conv->log.logE =
base == 2 base == 2
? M_LOG2E ? M_LOG2E
: base == M_E : base == M_E
? 1 ? 1
: base == 10 : base == 10
? M_LOG10E ? M_LOG10E
skipping to change at line 1078 skipping to change at line 1072
cv_converter* cv_converter*
cv_get_pow( cv_get_pow(
const double base) const double base)
{ {
cv_converter* conv; cv_converter* conv;
if (base <= 0) { if (base <= 0) {
conv = NULL; conv = NULL;
} }
else { else {
conv = malloc(sizeof(ExpConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->ops = &expOps; conv->ops = &expOps;
conv->exp.base = base; conv->exp.base = base;
} }
} }
return conv; return conv;
} }
skipping to change at line 1187 skipping to change at line 1181
/* /*
* General case: create a composite converter. * General case: create a composite converter.
*/ */
cv_converter* c1 = CV_CLONE(first); cv_converter* c1 = CV_CLONE(first);
int error = 1; int error = 1;
if (c1 != NULL) { if (c1 != NULL) {
cv_converter* c2 = CV_CLONE(second); cv_converter* c2 = CV_CLONE(second);
if (c2 != NULL) { if (c2 != NULL) {
conv = malloc(sizeof(CompositeConverter)); conv = malloc(sizeof(*conv));
if (conv != NULL) { if (conv != NULL) {
conv->composite.ops = &compositeOps; conv->composite.ops = &compositeOps;
conv->composite.first = c1; conv->composite.first = c1;
conv->composite.second = c2; conv->composite.second = c2;
error = 0; error = 0;
} /* "conv" allocated */ } /* "conv" allocated */
if (error) if (error)
cv_free(c2); cv_free(c2);
 End of changes. 9 change blocks. 
16 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)