~ubuntu-branches/ubuntu/lucid/gauche-c-wrapper/lucid

« back to all changes in this revision

Viewing changes to libffi/testsuite/libffi.call/float2.c

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2008-04-07 09:15:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080407091503-wu0h414koe95kj4i
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Area:        ffi_call
 
2
   Purpose:     Check return value long double.
 
3
   Limitations: none.
 
4
   PR:          none.
 
5
   Originator:  From the original ffitest.c  */
 
6
 
 
7
/* { dg-do run } */
 
8
 
 
9
#include "ffitest.h"
 
10
#include "float.h"
 
11
 
 
12
static long double ldblit(float f)
 
13
{
 
14
  return (long double) (((long double) f)/ (long double) 3.0);
 
15
}
 
16
 
 
17
int main (void)
 
18
{
 
19
  ffi_cif cif;
 
20
  ffi_type *args[MAX_ARGS];
 
21
  void *values[MAX_ARGS];
 
22
  float f;
 
23
  long double ld;
 
24
 
 
25
  args[0] = &ffi_type_float;
 
26
  values[0] = &f;
 
27
 
 
28
  /* Initialize the cif */
 
29
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
 
30
                     &ffi_type_longdouble, args) == FFI_OK);
 
31
 
 
32
  f = 3.14159;
 
33
 
 
34
#if 1
 
35
  /* This is ifdef'd out for now. long double support under SunOS/gcc
 
36
     is pretty much non-existent.  You'll get the odd bus error in library
 
37
     routines like printf().  */
 
38
  printf ("%Lf\n", ldblit(f));
 
39
#endif
 
40
  ld = 666;
 
41
  ffi_call(&cif, FFI_FN(ldblit), &ld, values);
 
42
 
 
43
#if 1
 
44
  /* This is ifdef'd out for now. long double support under SunOS/gcc
 
45
     is pretty much non-existent.  You'll get the odd bus error in library
 
46
     routines like printf().  */
 
47
  printf ("%Lf, %Lf, %Lf, %Lf\n", ld, ldblit(f), ld - ldblit(f), LDBL_EPSILON);
 
48
#endif
 
49
 
 
50
  /* These are not always the same!! Check for a reasonable delta */
 
51
  /*@-realcompare@*/
 
52
  if (ld - ldblit(f) < LDBL_EPSILON)
 
53
    /*@=realcompare@*/
 
54
    puts("long double return value tests ok!");
 
55
  else
 
56
    CHECK(0);
 
57
 
 
58
  exit(0);
 
59
}