Files
SaraP bf3a3fa297 Extern :
- aggiunta libreria vroni 7.6.
2023-11-23 12:09:32 +01:00

232 lines
6.4 KiB
C++

/*****************************************************************************/
/* */
/* Copyright (C) 1999-2023 M. Held */
/* */
/* This code is not in the public domain. All rights reserved! Please make */
/* sure to read the full copyright statement contained in "README.txt" or in */
/* the "main" file of this code, such as "main.cc". */
/* */
/*****************************************************************************/
/* */
/* Written by: Martin Held */
/* */
/* E-Mail: held@cs.sbg.ac.at */
/* Fax Mail: (+43 662) 8044-611 */
/* Voice Mail: (+43 662) 8044-6304 */
/* Snail Mail: Martin Held */
/* FB Informatik */
/* Universitaet Salzburg */
/* A-5020 Salzburg, Austria */
/* */
/*****************************************************************************/
#ifndef VRONI_FP_KERNEL_H
#define VRONI_FP_KERNEL_H
#ifdef WITH_COREBACKEND
/* Set CORE Level to 4. Otherwise all unsigned long no longer work */
#define CORE_LEVEL 4
#ifdef WITH_CORE_EXPR_WRAPPER
#include<ExprWrapper.h>
#else
#include<CORE/CORE.h>
#endif /* WITH_CORE_EXPR_WRAPPER */
#undef double
#ifdef WITH_COREBACKEND_BIGFLOAT
#define double CORE::BigFloat
#else
/* allow double to be used as Expr */
#define double Expr
#endif
#define double_arg const double &
//This is used to indicate that double gets a different meaning!
#define DOUBLE_OVERRIDE
#include <formattedIO.h>
#define TO_MDOUBLE(x) (x).doubleValue()
inline CORE::BigInt cut_comma(const Expr & x) {
CORE::BigInt v = floor(x);
if(v < 0) {
return v + 1;
} else {
return v;
}
}
#include "coreatan2.h"
inline int intfloor(const Expr & e) {
return floor(e).intValue();
}
inline unsigned int uintceil(const Expr & e) {
return (unsigned)ceil(e).intValue();
}
//REAL_TO_INT behaves like (int)(x)
#define REAL_TO_INT(x) cut_comma(x).intValue()
#define REAL_TO_GLINT(x) cut_comma(x).intValue()
#define REAL_TO_FLOAT(x) (x).floatValue()
#define BIGINT_TO_INT(x) (x).intValue()
#define TO_REAL(x) double(x)
//Definitions for functions undefined in CORE
#define isnan(x) 0
#define atan2(y,x) atan2local((y),(x))
#define signbit(x) ((x) < 0 ? 1 : 0)
#define CORE_EXPR_OPS(name, x) { \
std::map<std::string, unsigned int > m; \
(x).rep()->rekCollectOp(m); \
for(std::map<std::string, unsigned int>::iterator it = m.begin(); it != m.end(); ++it) { \
std::cout << it->second << "\t: " << it->first << std::endl; \
}}
#ifdef WITH_CORE_EXPR_WRAPPER
inline void CORE_EXPR_SEQ(std::string name, const Expr & x) {
std::map<unsigned int, std::string > m;
(x).rep()->rekSequen(m);
for (std::map<unsigned int, std::string>::iterator it = m.begin(); it != m.end(); ++it) {
std::cout << it->second << std::endl;
}
}
inline void CORE_EXPR_DEBUG1(std::string name, const Expr & x) {
std::cout << name << " depth: " << (x).rep()->getDepth() << std::endl;
std::cout << name << " elementCount: " << (x).rep()->getElementCount() << std::endl;
CORE_EXPR_SEQ(name, (x));
std::cout << name << " value: " << (x) << std::endl;
}
#else
inline void CORE_EXPR_SEQ(std::string name, const Expr & x) {}
inline void CORE_EXPR_DEBUG1(std::string name, const Expr & x) {}
#endif
//IO
#define FP_printf formattedIO::fmc_printf
#define FP_fprintf formattedIO::fmc_fprintf
inline const double * FP_PRNTARG(const double & x) { return &x; }
//[sf]scanf methods
#define FP_fscanf formattedIO::cfscanf
#define FP_sscanf formattedIO::csscanf
// The second argument is the SHA1sum of "shift\n". This avoids a
// conflict with a shift function in CORE - VRONI uses some
// variables named shift
#define shift a68fe7dac8c32f30ad04d52fab4aa46be1068d82
#elif defined(WITH_MPFRBACKEND)
#include <mpfr_class.h>
#include <formattedIO.h>
typedef double machine_double;
#undef double
#ifdef WITH_CORE_EXPR_WRAPPER
#include<ExprWrapper.h>
#define double Expr<Mpfr_class>
#else
#define double Mpfr_class
#endif /* WITH_CORE_EXPR_WRAPPER */
#define double_arg const double &
//This is used to indicate that double gets a different meaning!
#define DOUBLE_OVERRIDE
#define TO_MDOUBLE(x) (x).doubleValue()
#define REAL_TO_INT(x) (x).intValue()
#define REAL_TO_GLINT(x) (x).intValue()
#define REAL_TO_FLOAT(x) (x).floatValue()
#define TO_REAL(x) double(x)
inline void CORE_EXPR_DEBUG1(std::string , const double & ) {}
inline long intfloor(const double & e) {
return floor(e).intValue();
}
inline unsigned long uintceil(const double & e) {
return ceil(e).intValue();
}
//Definitions for functions undefined in CORE
#if WITH_CORE_EXPR_WRAPPER
#define is_nan(x) 0
#define sign_bit(x) ((x) < 0 ? 1 : 0)
#endif
//IO
#define FP_printf formattedIO::fmc_printf
#define FP_fprintf formattedIO::fmc_fprintf
inline const double * FP_PRNTARG(const double & x) { return &x; }
//[sf]scanf methods
#define FP_fscanf formattedIO::cfscanf
#define FP_sscanf formattedIO::csscanf
#else
#include <math.h>
#define TO_MDOUBLE(x) (x)
#define REAL_TO_INT(x) (int)(x)
#define REAL_TO_GLINT(x) (GLint)(x)
#define REAL_TO_FLOAT(x) (float)(x)
#define BIGINT_TO_INT(x) (x)
#define TO_REAL(x) (x)
#define machine_double double
#define double_arg double
inline int intfloor(const double e) {
return (int)(floor(e));
}
inline unsigned int uintceil(const double e) {
return (unsigned)ceil(e);
}
#define CORE_EXPR_DEBUG1(x,y)
#define is_nan(x) isnan(x)
#define sign_bit(x) signbit(x)
#ifdef DOUBLE_OVERRIDE
#error "DOUBLE_OVERRIDE should not be defined here!"
#endif
//IO
#define FP_printf printf
#define FP_fprintf fprintf
#define FP_PRNTARG(x) (x)
//[sf]scanf methods
#define FP_fscanf fscanf
#define FP_sscanf sscanf
#endif /* LIB_CORE */
#endif /* VRONI_FP_KERNEL_H */