summaryrefslogtreecommitdiff
path: root/libguile/num2float.i.c
blob: 5ef3a30cfe4ab2427296d53c496ed6c501cbd8de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* this file is #include'd (several times) by numbers.c */

FTYPE
NUM2FLOAT (SCM num, unsigned long int pos, const char *s_caller)
{
  if (SCM_INUMP (num))
    return SCM_INUM (num);
  else if (SCM_BIGP (num))
    { /* bignum */
      FTYPE res = mpz_get_d (SCM_I_BIG_MPZ (num));
      if (isfinite (res))
	return res;
      else
	scm_out_of_range (s_caller, num);
    }
  else if (SCM_REALP (num))
    return SCM_REAL_VALUE (num);
  else
    scm_wrong_type_arg (s_caller, pos, num);
}

SCM
FLOAT2NUM (FTYPE n)
{
  SCM z = scm_double_cell (scm_tc16_real, 0, 0, 0);
  SCM_REAL_VALUE (z) = n;
  return z;
}

/* clean up */
#undef FLOAT2NUM
#undef NUM2FLOAT
#undef FTYPE

/*
  Local Variables:
  c-file-style: "gnu"
  End:
*/