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