Back to index

plt-scheme  4.2.1
Defines | Functions
numcomp.c File Reference
#include "schpriv.h"
#include "nummacs.h"
#include <math.h>

Go to the source code of this file.

Defines

#define zeroi   scheme_exact_zero
#define EQUAL(x, y)   (x == y)
#define LESS_THAN(x, y)   (x < y)
#define GREATER_THAN(x, y)   (x > y)
#define LESS_OR_EQUAL(x, y)   (x <= y)
#define GREATER_OR_EQUAL(x, y)   (x >= y)
#define fLESS_THAN   LESS_THAN
#define fLESS_OR_EQUAL   LESS_OR_EQUAL
#define COMP_IZI_LT(a, b)   scheme_bin_lt(IZI_REAL_PART(a), IZI_REAL_PART(b))
#define COMP_IZI_GT(a, b)   scheme_bin_gt(IZI_REAL_PART(a), IZI_REAL_PART(b))
#define COMP_IZI_LT_EQ(a, b)   scheme_bin_lt_eq(IZI_REAL_PART(a), IZI_REAL_PART(b))
#define COMP_IZI_GT_EQ(a, b)   scheme_bin_gt_eq(IZI_REAL_PART(a), IZI_REAL_PART(b))
#define GEN_IDENT_FOR_IZI   GEN_OMIT
#define MAX(n1, n2)   scheme_make_integer((n1>n2) ? n1 : n2)
#define MIN(n1, n2)   scheme_make_integer((n1<n2) ? n1 : n2)
#define F_MAX(n1, n2)   scheme_make_double((n1>n2) ? n1 : n2)
#define F_MIN(n1, n2)   scheme_make_double((n1<n2) ? n1 : n2)
#define FS_MAX(n1, n2)   scheme_make_float((n1>n2) ? n1 : n2)
#define FS_MIN(n1, n2)   scheme_make_float((n1<n2) ? n1 : n2)
#define MAX_IZI(a, b)   bin_max(IZI_REAL_PART(a), IZI_REAL_PART(b))
#define MIN_IZI(a, b)   bin_min(IZI_REAL_PART(a), IZI_REAL_PART(b))

Functions

static Scheme_Objecteq (int argc, Scheme_Object *argv[])
static Scheme_Objectlt (int argc, Scheme_Object *argv[])
static Scheme_Objectgt (int argc, Scheme_Object *argv[])
static Scheme_Objectlt_eq (int argc, Scheme_Object *argv[])
static Scheme_Objectgt_eq (int argc, Scheme_Object *argv[])
static Scheme_Objectzero_p (int argc, Scheme_Object *argv[])
static Scheme_Objectpositive_p (int argc, Scheme_Object *argv[])
static Scheme_Objectnegative_p (int argc, Scheme_Object *argv[])
static Scheme_Objectsch_max (int argc, Scheme_Object *argv[])
static Scheme_Objectsch_min (int argc, Scheme_Object *argv[])
void scheme_init_numcomp (Scheme_Env *env)
static MZ_INLINE Scheme_Objectforce_rat (Scheme_Object *n, Small_Rational *sr)
int scheme_is_zero (const Scheme_Object *o)
int scheme_is_positive (const Scheme_Object *o)
int scheme_is_negative (const Scheme_Object *o)

Define Documentation

#define COMP_IZI_GT (   a,
  b 
)    scheme_bin_gt(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 129 of file numcomp.c.

#define COMP_IZI_GT_EQ (   a,
  b 
)    scheme_bin_gt_eq(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 131 of file numcomp.c.

#define COMP_IZI_LT (   a,
  b 
)    scheme_bin_lt(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 128 of file numcomp.c.

#define COMP_IZI_LT_EQ (   a,
  b 
)    scheme_bin_lt_eq(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 130 of file numcomp.c.

#define EQUAL (   x,
  y 
)    (x == y)

Definition at line 114 of file numcomp.c.

#define F_MAX (   n1,
  n2 
)    scheme_make_double((n1>n2) ? n1 : n2)

Definition at line 283 of file numcomp.c.

#define F_MIN (   n1,
  n2 
)    scheme_make_double((n1<n2) ? n1 : n2)

Definition at line 284 of file numcomp.c.

Definition at line 125 of file numcomp.c.

#define fLESS_THAN   LESS_THAN

Definition at line 124 of file numcomp.c.

#define FS_MAX (   n1,
  n2 
)    scheme_make_float((n1>n2) ? n1 : n2)

Definition at line 286 of file numcomp.c.

#define FS_MIN (   n1,
  n2 
)    scheme_make_float((n1<n2) ? n1 : n2)

Definition at line 287 of file numcomp.c.

Definition at line 133 of file numcomp.c.

#define GREATER_OR_EQUAL (   x,
  y 
)    (x >= y)

Definition at line 118 of file numcomp.c.

#define GREATER_THAN (   x,
  y 
)    (x > y)

Definition at line 116 of file numcomp.c.

#define LESS_OR_EQUAL (   x,
  y 
)    (x <= y)

Definition at line 117 of file numcomp.c.

#define LESS_THAN (   x,
  y 
)    (x < y)

Definition at line 115 of file numcomp.c.

#define MAX (   n1,
  n2 
)    scheme_make_integer((n1>n2) ? n1 : n2)

Definition at line 281 of file numcomp.c.

#define MAX_IZI (   a,
  b 
)    bin_max(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 289 of file numcomp.c.

#define MIN (   n1,
  n2 
)    scheme_make_integer((n1<n2) ? n1 : n2)

Definition at line 282 of file numcomp.c.

#define MIN_IZI (   a,
  b 
)    bin_min(IZI_REAL_PART(a), IZI_REAL_PART(b))

Definition at line 290 of file numcomp.c.

#define zeroi   scheme_exact_zero

Definition at line 41 of file numcomp.c.


Function Documentation

static Scheme_Object* eq ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

static MZ_INLINE Scheme_Object * force_rat ( Scheme_Object n,
Small_Rational sr 
) [static]

Definition at line 95 of file numcomp.c.

{
  Scheme_Type t = SCHEME_TYPE(n);
  if (t == scheme_rational_type)
    return n;
  else
    return scheme_make_small_bn_rational(n, sr);
}

Here is the call graph for this function:

static Scheme_Object* gt ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

static Scheme_Object* gt_eq ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

static Scheme_Object* lt ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

static Scheme_Object* lt_eq ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

Scheme_Object * negative_p ( int  argc,
Scheme_Object argv[] 
) [static]

Definition at line 270 of file numcomp.c.

{
  int v;
  v = scheme_is_negative(argv[0]);
  if (v < 0) {
    NEED_REAL(negative?);
    ESCAPED_BEFORE_HERE;
  }
  return (v ? scheme_true : scheme_false);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Scheme_Object * positive_p ( int  argc,
Scheme_Object argv[] 
) [static]

Definition at line 224 of file numcomp.c.

{
  int v;
  v = scheme_is_positive(argv[0]);
  if (v < 0) {
    NEED_REAL(positive?);
    ESCAPED_BEFORE_HERE;
  }
  return (v ? scheme_true : scheme_false);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Scheme_Object* sch_max ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

static Scheme_Object* sch_min ( int  argc,
Scheme_Object argv[] 
) [static]

Here is the caller graph for this function:

Definition at line 43 of file numcomp.c.

{
  Scheme_Object *p;

  p = scheme_make_folding_prim(eq, "=", 2, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant("=", p, env);

  p = scheme_make_folding_prim(lt, "<", 2, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant("<", p, env);

  p = scheme_make_folding_prim(gt, ">", 2, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant(">", p, env);

  p = scheme_make_folding_prim(lt_eq, "<=", 2, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant("<=", p, env);

  p = scheme_make_folding_prim(gt_eq, ">=", 2, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant(">=", p, env);

  p = scheme_make_folding_prim(zero_p, "zero?", 1, 1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
  scheme_add_global_constant("zero?", p, env);

  p = scheme_make_folding_prim(positive_p, "positive?", 1, 1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
  scheme_add_global_constant("positive?", p, env);

  p = scheme_make_folding_prim(negative_p, "negative?", 1, 1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_UNARY_INLINED;
  scheme_add_global_constant("negative?", p, env);

  p = scheme_make_folding_prim(sch_max, "max", 1, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant("max", p, env);

  p = scheme_make_folding_prim(sch_min, "min", 1, -1, 1);
  SCHEME_PRIM_PROC_FLAGS(p) |= SCHEME_PRIM_IS_BINARY_INLINED;
  scheme_add_global_constant("min", p, env);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 236 of file numcomp.c.

{
  Scheme_Type t;

  if (SCHEME_INTP(o))
    return SCHEME_INT_VAL(o) < 0;
  t = _SCHEME_TYPE(o);
#ifdef MZ_USE_SINGLE_FLOATS
  if (t == scheme_float_type) {
    float d = SCHEME_FLT_VAL(o);
# if defined(NAN_EQUALS_ANYTHING) || defined(NAN_LT_COMPARISON_WRONG)
    if (MZ_IS_NAN(d))
      return 0;
# endif
    return d < 0;
  }
#endif
  if (t == scheme_double_type) {
    double d = SCHEME_DBL_VAL(o);
# if defined(NAN_EQUALS_ANYTHING) || defined(NAN_LT_COMPARISON_WRONG)
    if (MZ_IS_NAN(d))
      return 0;
#endif
    return d < 0;
  }
  if (t == scheme_bignum_type)
    return !SCHEME_BIGPOS(o);
  if (t == scheme_rational_type)
    return !scheme_is_rational_positive(o);

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 190 of file numcomp.c.

{
  Scheme_Type t;

  if (SCHEME_INTP(o))
    return SCHEME_INT_VAL(o) > 0;
  t = _SCHEME_TYPE(o);
#ifdef MZ_USE_SINGLE_FLOATS
  if (t == scheme_float_type) {
    float d = SCHEME_FLT_VAL(o);
# ifdef NAN_EQUALS_ANYTHING
    if (MZ_IS_NAN(d))
      return 0;
# endif
    return d > 0;
  }
#endif
  if (t == scheme_double_type) {
    double d = SCHEME_DBL_VAL(o);
#ifdef NAN_EQUALS_ANYTHING
    if (MZ_IS_NAN(d))
      return 0;
#endif
    return d > 0;
  }
  if (t == scheme_bignum_type)
    return SCHEME_BIGPOS(o);
  if (t == scheme_rational_type)
    return scheme_is_rational_positive(o);

  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 142 of file numcomp.c.

{
  Scheme_Type t;

  if (SCHEME_INTP(o))
    return o == zeroi;
  t = _SCHEME_TYPE(o);
#ifdef MZ_USE_SINGLE_FLOATS
  if (t == scheme_float_type) {
# ifdef NAN_EQUALS_ANYTHING
    if (MZ_IS_NAN(SCHEME_FLT_VAL(o)))
      return 0;
# endif
    return SCHEME_FLT_VAL(o) == 0.0f;
  }
#endif
  if (t == scheme_double_type) {
#ifdef NAN_EQUALS_ANYTHING
    if (MZ_IS_NAN(SCHEME_DBL_VAL(o)))
      return 0;
#endif
    return SCHEME_DBL_VAL(o) == 0.0;
  }
  if (t == scheme_complex_type) {
    if (scheme_is_zero(scheme_complex_imaginary_part(o)))
      return scheme_is_zero(scheme_complex_real_part(o));
    return 0;
  }
  
  if ((t >= scheme_bignum_type) && (t <= scheme_complex_type))
    return 0;
 
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Scheme_Object * zero_p ( int  argc,
Scheme_Object argv[] 
) [static]

Definition at line 178 of file numcomp.c.

{
  int v;
  v = scheme_is_zero(argv[0]);
  if (v < 0) {
    NEED_REAL(zero?);
    ESCAPED_BEFORE_HERE;
  }
  return (v ? scheme_true : scheme_false);
}

Here is the call graph for this function:

Here is the caller graph for this function: