AlmostEqualUlps on central place
This commit is contained in:
parent
c45bc50421
commit
b7e71db2ad
|
|
@ -1,4 +1,3 @@
|
||||||
#include <assert.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
#include "cpdefs.h"
|
#include "cpdefs.h"
|
||||||
|
|
@ -8,29 +7,12 @@
|
||||||
#include "rawfile.h"
|
#include "rawfile.h"
|
||||||
#include "variable.h"
|
#include "variable.h"
|
||||||
#include "numparam/numpaif.h"
|
#include "numparam/numpaif.h"
|
||||||
|
#include "missing_math.h"
|
||||||
|
|
||||||
static bool measure_valid[20000];
|
static bool measure_valid[20000];
|
||||||
static bool just_chk_meas;
|
static bool just_chk_meas;
|
||||||
static bool measures_passed;
|
static bool measures_passed;
|
||||||
|
|
||||||
// Initial AlmostEqualULPs version - fast and simple, but
|
|
||||||
// some limitations.
|
|
||||||
static bool AlmostEqualUlps(float A, float B, int maxUlps)
|
|
||||||
{
|
|
||||||
int intDiff;
|
|
||||||
assert(sizeof(float) == sizeof(int));
|
|
||||||
|
|
||||||
if (A == B)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
intDiff = abs(*(int*)&A - *(int*)&B);
|
|
||||||
|
|
||||||
if (intDiff <= maxUlps)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double
|
static double
|
||||||
max( double a, double b ) {
|
max( double a, double b ) {
|
||||||
if ( a > b ) return a;
|
if ( a > b ) return a;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ Copyright 1999 Emmanuel Rouat
|
||||||
|
|
||||||
/* Decl. for missing maths functions, if any */
|
/* Decl. for missing maths functions, if any */
|
||||||
|
|
||||||
|
#ifndef MISSING_MATH_H_INCLUDED
|
||||||
|
#define MISSING_MATH_H_INCLUDED
|
||||||
|
|
||||||
|
bool AlmostEqualUlps(float, float, int);
|
||||||
|
|
||||||
#ifndef HAVE_ERFC
|
#ifndef HAVE_ERFC
|
||||||
extern double erfc(double);
|
extern double erfc(double);
|
||||||
|
|
@ -23,3 +27,5 @@ extern double scalb(double, int);
|
||||||
#ifndef HAVE_ISNAN
|
#ifndef HAVE_ISNAN
|
||||||
extern int isnan(double);
|
extern int isnan(double);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif /* MISSING_MATH_H_INCLUDED */
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,28 @@ $Id$
|
||||||
/*
|
/*
|
||||||
* Missing math functions
|
* Missing math functions
|
||||||
*/
|
*/
|
||||||
#include <config.h>
|
#include <assert.h>
|
||||||
|
#include "config.h"
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include "missing_math.h"
|
#include "missing_math.h"
|
||||||
|
|
||||||
|
/* Initial AlmostEqualULPs version - fast and simple, but */
|
||||||
|
/* some limitations. */
|
||||||
|
bool AlmostEqualUlps(float A, float B, int maxUlps)
|
||||||
|
{
|
||||||
|
int intDiff;
|
||||||
|
assert(sizeof(float) == sizeof(int));
|
||||||
|
|
||||||
|
if (A == B)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
intDiff = abs(*(int*)&A - *(int*)&B);
|
||||||
|
|
||||||
|
if (intDiff <= maxUlps)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef HAVE_LOGB
|
#ifndef HAVE_LOGB
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@
|
||||||
#ifndef MISSING_MATH_H_INCLUDED
|
#ifndef MISSING_MATH_H_INCLUDED
|
||||||
#define MISSING_MATH_H_INCLUDED
|
#define MISSING_MATH_H_INCLUDED
|
||||||
|
|
||||||
|
bool AlmostEqualUlps(float, float, int);
|
||||||
|
|
||||||
#ifndef HAVE_ERFC
|
#ifndef HAVE_ERFC
|
||||||
double erfc(double);
|
double erfc(double);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -21,7 +23,7 @@ double scalb(double, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_ISNAN
|
#ifndef HAVE_ISNAN
|
||||||
int isnan(double value);
|
int isnan(double);
|
||||||
#endif /* HAVE_ISNAN */
|
#endif
|
||||||
|
|
||||||
#endif /* MISSING_MATH_H_INCLUDED */
|
#endif /* MISSING_MATH_H_INCLUDED */
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,19 @@ Modified: 2000 AlansFixes
|
||||||
/* subroutine to do DC TRANSIENT analysis
|
/* subroutine to do DC TRANSIENT analysis
|
||||||
--- ONLY, unlike spice2 routine with the same name! */
|
--- ONLY, unlike spice2 routine with the same name! */
|
||||||
|
|
||||||
#include <assert.h>
|
#include "ngspice.h"
|
||||||
#include <ngspice.h>
|
#include "config.h"
|
||||||
#include <config.h>
|
#include "cktdefs.h"
|
||||||
#include <cktdefs.h>
|
#include "cktaccept.h"
|
||||||
#include <cktaccept.h>
|
#include "trandefs.h"
|
||||||
#include <trandefs.h>
|
#include "sperror.h"
|
||||||
#include <sperror.h>
|
|
||||||
#include "fteext.h"
|
#include "fteext.h"
|
||||||
|
#include "missing_math.h"
|
||||||
|
|
||||||
#ifdef XSPICE
|
#ifdef XSPICE
|
||||||
/* gtri - add - wbk - Add headers */
|
/* gtri - add - wbk - Add headers */
|
||||||
#include "miftypes.h"
|
#include "miftypes.h"
|
||||||
/* gtri - end - wbk - Add headers */
|
|
||||||
|
|
||||||
/* gtri - add - wbk - Add headers */
|
|
||||||
#include "evt.h"
|
#include "evt.h"
|
||||||
#include "mif.h"
|
#include "mif.h"
|
||||||
#include "evtproto.h"
|
#include "evtproto.h"
|
||||||
|
|
@ -37,24 +35,6 @@ Modified: 2000 AlansFixes
|
||||||
void SetAnalyse( char * Analyse, int Percent);
|
void SetAnalyse( char * Analyse, int Percent);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initial AlmostEqualULPs version - fast and simple, but
|
|
||||||
// some limitations.
|
|
||||||
static bool AlmostEqualUlps(float A, float B, int maxUlps)
|
|
||||||
{
|
|
||||||
int intDiff;
|
|
||||||
assert(sizeof(float) == sizeof(int));
|
|
||||||
|
|
||||||
if (A == B)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
intDiff = abs(*(int*)&A - *(int*)&B);
|
|
||||||
|
|
||||||
if (intDiff <= maxUlps)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
DCtran(CKTcircuit *ckt,
|
DCtran(CKTcircuit *ckt,
|
||||||
int restart) /* forced restart flag */
|
int restart) /* forced restart flag */
|
||||||
|
|
|
||||||
|
|
@ -4,30 +4,12 @@ Author: 1985 Thomas L. Quarles
|
||||||
Modified: Apr 2000 - Paolo Nenzi
|
Modified: Apr 2000 - Paolo Nenzi
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "ifsim.h"
|
#include "ifsim.h"
|
||||||
#include "resdefs.h"
|
#include "resdefs.h"
|
||||||
#include "sperror.h"
|
#include "sperror.h"
|
||||||
|
#include "missing_math.h"
|
||||||
// Initial AlmostEqualULPs version - fast and simple, but
|
|
||||||
// some limitations.
|
|
||||||
static bool AlmostEqualUlps(float A, float B, int maxUlps)
|
|
||||||
{
|
|
||||||
int intDiff;
|
|
||||||
assert(sizeof(float) == sizeof(int));
|
|
||||||
|
|
||||||
if (A == B)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
intDiff = abs(*(int*)&A - *(int*)&B);
|
|
||||||
|
|
||||||
if (intDiff <= maxUlps)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
|
RESparam(int param, IFvalue *value, GENinstance *inst, IFvalue *select)
|
||||||
|
|
|
||||||
|
|
@ -3,36 +3,17 @@ Copyright 1990 Regents of the University of California. All rights reserved.
|
||||||
Author: 1985 Thomas L. Quarles
|
Author: 1985 Thomas L. Quarles
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include "ngspice.h"
|
#include "ngspice.h"
|
||||||
#include "cktdefs.h"
|
#include "cktdefs.h"
|
||||||
#include "vsrcdefs.h"
|
#include "vsrcdefs.h"
|
||||||
#include "trandefs.h"
|
#include "trandefs.h"
|
||||||
#include "sperror.h"
|
#include "sperror.h"
|
||||||
#include "suffix.h"
|
#include "suffix.h"
|
||||||
|
#include "missing_math.h"
|
||||||
|
|
||||||
#define SAMETIME(a,b) (fabs((a)-(b))<= TIMETOL * PW)
|
#define SAMETIME(a,b) (fabs((a)-(b))<= TIMETOL * PW)
|
||||||
#define TIMETOL 1e-7
|
#define TIMETOL 1e-7
|
||||||
|
|
||||||
// Initial AlmostEqualULPs version - fast and simple, but
|
|
||||||
// some limitations.
|
|
||||||
static bool AlmostEqualUlps(float A, float B, int maxUlps)
|
|
||||||
{
|
|
||||||
int intDiff;
|
|
||||||
assert(sizeof(float) == sizeof(int));
|
|
||||||
|
|
||||||
if (A == B)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
intDiff = abs(*(int*)&A - *(int*)&B);
|
|
||||||
|
|
||||||
if (intDiff <= maxUlps)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
|
VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
|
||||||
/* set up the breakpoint table.
|
/* set up the breakpoint table.
|
||||||
|
|
@ -101,12 +82,8 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
|
||||||
#endif
|
#endif
|
||||||
/* gtri - end - wbk - add PHASE parameter */
|
/* gtri - end - wbk - add PHASE parameter */
|
||||||
|
|
||||||
|
|
||||||
time = ckt->CKTtime - TD;
|
time = ckt->CKTtime - TD;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(time >= PER) {
|
if(time >= PER) {
|
||||||
/* repeating signal - figure out where we are */
|
/* repeating signal - figure out where we are */
|
||||||
/* in period */
|
/* in period */
|
||||||
|
|
@ -190,8 +167,8 @@ VSRCaccept(CKTcircuit *ckt, GENmodel *inModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) {
|
for(i=0;i<(here->VSRCfunctionOrder/2)-1;i++) {
|
||||||
//if((*(here->VSRCcoeffs+2*i)==ckt->CKTtime)) {
|
/* if((*(here->VSRCcoeffs+2*i)==ckt->CKTtime)) {
|
||||||
// if(ckt->CKTbreak) {
|
if(ckt->CKTbreak) {*/
|
||||||
if ( ckt->CKTbreak && AlmostEqualUlps(*(here->VSRCcoeffs+2*i), ckt->CKTtime, 3 ) ) {
|
if ( ckt->CKTbreak && AlmostEqualUlps(*(here->VSRCcoeffs+2*i), ckt->CKTtime, 3 ) ) {
|
||||||
error = CKTsetBreak(ckt, *(here->VSRCcoeffs+2*i+2));
|
error = CKTsetBreak(ckt, *(here->VSRCcoeffs+2*i+2));
|
||||||
if(error) return(error);
|
if(error) return(error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue