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

« back to all changes in this revision

Viewing changes to libffi/testsuite/libffi.call/float.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 float.
 
3
   Limitations: none.
 
4
   PR:          none.
 
5
   Originator:  From the original ffitest.c  */
 
6
 
 
7
/* { dg-do run } */
 
8
 
 
9
#include "ffitest.h"
 
10
 
 
11
static int floating(int a, float b, double c, long double d, int e)
 
12
{
 
13
  int i;
 
14
 
 
15
  i = (int) ((float)a/b + ((float)c/(float)d));
 
16
 
 
17
  return i;
 
18
}
 
19
 
 
20
int main (void)
 
21
{
 
22
  ffi_cif cif;
 
23
  ffi_type *args[MAX_ARGS];
 
24
  void *values[MAX_ARGS];
 
25
  ffi_arg rint;
 
26
 
 
27
  float f;
 
28
  signed int si1;
 
29
  double d;
 
30
  long double ld;
 
31
  signed int si2;
 
32
 
 
33
  args[0] = &ffi_type_sint;
 
34
  values[0] = &si1;
 
35
  args[1] = &ffi_type_float;
 
36
  values[1] = &f;
 
37
  args[2] = &ffi_type_double;
 
38
  values[2] = &d;
 
39
  args[3] = &ffi_type_longdouble;
 
40
  values[3] = &ld;
 
41
  args[4] = &ffi_type_sint;
 
42
  values[4] = &si2;
 
43
 
 
44
  /* Initialize the cif */
 
45
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 5,
 
46
                     &ffi_type_sint, args) == FFI_OK);
 
47
 
 
48
  si1 = 6;
 
49
  f = 3.14159;
 
50
  d = (double)1.0/(double)3.0;
 
51
  ld = 2.71828182846L;
 
52
  si2 = 10;
 
53
 
 
54
  floating (si1, f, d, ld, si2);
 
55
 
 
56
  ffi_call(&cif, FFI_FN(floating), &rint, values);
 
57
 
 
58
  printf ("%d vs %d\n", (int)rint, floating (si1, f, d, ld, si2));
 
59
 
 
60
  CHECK(rint == floating(si1, f, d, ld, si2));
 
61
 
 
62
  exit (0);
 
63
}