~peter-pearse/ubuntu/natty/guile-1.8/prop001

« back to all changes in this revision

Viewing changes to test-suite/standalone/test-conversion.c

  • Committer: Bazaar Package Importer
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2009-07-20 19:39:17 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20090720193917-s0985l9wxihwoscl
Tags: 1.8.7+1-1ubuntu1
* Merge from Debian unstable, remaining changes: (LP: #401816)
  - Build with -Wno-error.
  - Build with thread support. Some guile-using programs like autogen need it.
  - Add debian/guile-1.8-libs.shlibs: Thread support breaks ABI, bump the soname.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 1999,2000,2001,2003,2004, 2006, 2007, 2008 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1999,2000,2001,2003,2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
2
2
 *
3
3
 * This library is free software; you can redistribute it and/or
4
4
 * modify it under the terms of the GNU Lesser General Public
680
680
#define DEFSTST(f) static scm_t_intmax  tst_##f (SCM x) { return f(x); }
681
681
#define DEFUTST(f) static scm_t_uintmax tst_##f (SCM x) { return f(x); }
682
682
 
683
 
DEFSTST (scm_to_schar);
684
 
DEFUTST (scm_to_uchar);
685
 
DEFSTST (scm_to_char);
686
 
DEFSTST (scm_to_short);
687
 
DEFUTST (scm_to_ushort);
688
 
DEFSTST (scm_to_int);
689
 
DEFUTST (scm_to_uint);
690
 
DEFSTST (scm_to_long);
691
 
DEFUTST (scm_to_ulong);
 
683
DEFSTST (scm_to_schar)
 
684
DEFUTST (scm_to_uchar)
 
685
DEFSTST (scm_to_char)
 
686
DEFSTST (scm_to_short)
 
687
DEFUTST (scm_to_ushort)
 
688
DEFSTST (scm_to_int)
 
689
DEFUTST (scm_to_uint)
 
690
DEFSTST (scm_to_long)
 
691
DEFUTST (scm_to_ulong)
692
692
#if SCM_SIZEOF_LONG_LONG != 0
693
 
DEFSTST (scm_to_long_long);
694
 
DEFUTST (scm_to_ulong_long);
 
693
DEFSTST (scm_to_long_long)
 
694
DEFUTST (scm_to_ulong_long)
695
695
#endif
696
 
DEFSTST (scm_to_ssize_t);
697
 
DEFUTST (scm_to_size_t);
 
696
DEFSTST (scm_to_ssize_t)
 
697
DEFUTST (scm_to_size_t)
698
698
 
699
 
DEFSTST (scm_to_int8);
700
 
DEFUTST (scm_to_uint8);
701
 
DEFSTST (scm_to_int16);
702
 
DEFUTST (scm_to_uint16);
703
 
DEFSTST (scm_to_int32);
704
 
DEFUTST (scm_to_uint32);
 
699
DEFSTST (scm_to_int8)
 
700
DEFUTST (scm_to_uint8)
 
701
DEFSTST (scm_to_int16)
 
702
DEFUTST (scm_to_uint16)
 
703
DEFSTST (scm_to_int32)
 
704
DEFUTST (scm_to_uint32)
705
705
#ifdef SCM_HAVE_T_INT64
706
 
DEFSTST (scm_to_int64);
707
 
DEFUTST (scm_to_uint64);
 
706
DEFSTST (scm_to_int64)
 
707
DEFUTST (scm_to_uint64)
708
708
#endif
709
709
 
710
710
#define TEST_8S(v,f,r,re,te) test_8s (v, tst_##f, #f, r, re, te)
818
818
    }
819
819
}
820
820
 
 
821
/* The `infinity' and `not-a-number' values.  */
 
822
static double guile_Inf, guile_NaN;
 
823
 
 
824
/* Initialize GUILE_INF and GUILE_NAN.  Taken from `guile_ieee_init ()' in
 
825
   `libguile/numbers.c'.  */
 
826
static void
 
827
ieee_init (void)
 
828
{
 
829
#ifdef INFINITY
 
830
  /* C99 INFINITY, when available.
 
831
     FIXME: The standard allows for INFINITY to be something that overflows
 
832
     at compile time.  We ought to have a configure test to check for that
 
833
     before trying to use it.  (But in practice we believe this is not a
 
834
     problem on any system guile is likely to target.)  */
 
835
  guile_Inf = INFINITY;
 
836
#elif HAVE_DINFINITY
 
837
  /* OSF */
 
838
  extern unsigned int DINFINITY[2];
 
839
  guile_Inf = (*((double *) (DINFINITY)));
 
840
#else
 
841
  double tmp = 1e+10;
 
842
  guile_Inf = tmp;
 
843
  for (;;)
 
844
    {
 
845
      guile_Inf *= 1e+10;
 
846
      if (guile_Inf == tmp)
 
847
        break;
 
848
      tmp = guile_Inf;
 
849
    }
 
850
#endif
 
851
 
 
852
#ifdef NAN
 
853
  /* C99 NAN, when available */
 
854
  guile_NaN = NAN;
 
855
#elif HAVE_DQNAN
 
856
  {
 
857
    /* OSF */
 
858
    extern unsigned int DQNAN[2];
 
859
    guile_NaN = (*((double *)(DQNAN)));
 
860
  }
 
861
#else
 
862
  guile_NaN = guile_Inf / guile_Inf;
 
863
#endif
 
864
}
 
865
 
821
866
static void
822
867
test_from_double ()
823
868
{
824
869
  test_9 (12, "12.0");
825
870
  test_9 (0.25, "0.25");
826
871
  test_9 (0.1, "0.1");
827
 
  test_9 (1.0/0.0, "+inf.0");
828
 
  test_9 (-1.0/0.0, "-inf.0");
829
 
  test_9 (0.0/0.0, "+nan.0");
 
872
  test_9 (guile_Inf, "+inf.0");
 
873
  test_9 (-guile_Inf, "-inf.0");
 
874
  test_9 (guile_NaN, "+nan.0");
830
875
}
831
876
 
832
877
typedef struct {
880
925
  test_10 ("12",         12.0,  0);
881
926
  test_10 ("0.25",       0.25,  0);
882
927
  test_10 ("1/4",        0.25,  0);
883
 
  test_10 ("+inf.0",  1.0/0.0,  0);
884
 
  test_10 ("-inf.0", -1.0/0.0,  0);
 
928
  test_10 ("+inf.0", guile_Inf, 0);
 
929
  test_10 ("-inf.0",-guile_Inf, 0);
885
930
  test_10 ("+1i",         0.0,  1);
886
931
}
887
932
 
1056
1101
int
1057
1102
main (int argc, char *argv[])
1058
1103
{
 
1104
  ieee_init ();
1059
1105
  scm_boot_guile (argc, argv, tests, NULL);
1060
1106
  return 0;
1061
1107
}