phcpack_2.4.88_e448e94a/src/Ada/CtoPHC/State/assignments_of_solutions.adb

  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
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
with Interfaces.C;                      use Interfaces.C;
with Standard_Integer_Numbers;          use Standard_Integer_Numbers;
with Standard_Floating_Numbers;         use Standard_Floating_Numbers;
with Standard_Complex_Numbers;
with Double_Double_Numbers;             use Double_Double_Numbers;
with DoblDobl_Complex_Numbers;
with Quad_Double_Numbers;               use Quad_Double_Numbers;
with QuadDobl_Complex_Numbers;
with Standard_Floating_Vectors;
with Assignments_in_Ada_and_C;          use Assignments_in_Ada_and_C;

package body Assignments_of_Solutions is

-- AUXILIARIES :

  function DoblDobl_Create
              ( x : C_Double_Array; i : integer32 ) return double_double is

  -- DESCRIPTION :
  --   Returns a double double from x(i) and x(i+1).
 
    res : constant double_double
        := create(double_float(x(Interfaces.C.size_t(i))),
                  double_float(x(Interfaces.C.size_t(i+1))));

  begin
    return res;
  end DoblDobl_Create;

  function QuadDobl_Create
              ( x : C_Double_Array; i : integer32 ) return quad_double is

  -- DESCRIPTION :
  --   Returns a quad double from x(i), x(i+1), x(i+2), x(i+3).
 
    res_hi : constant double_double := DoblDobl_Create(x,i);
    res_lo : constant double_double := DoblDobl_Create(x,i+2);
    res : constant quad_double := create(res_hi,res_lo);

  begin
    return res;
  end QuadDobl_Create;

  function DoblDobl_Complex_Create
              ( x : C_Double_Array; i : integer32 )
              return DoblDobl_Complex_Numbers.Complex_Number is

  -- DESCRIPTION :
  --   Returns a complex double double with real part in x(i) and x(i+1)
  --   and imaginary part in x(i+2) and x(i+3).
 
    res_re : constant double_double := DoblDobl_Create(x,i);
    res_im : constant double_double := DoblDobl_Create(x,i+2);
    res : constant DoblDobl_Complex_Numbers.Complex_Number
        := DoblDobl_Complex_Numbers.Create(res_re,res_im);

  begin
    return res;
  end DoblDobl_Complex_Create;

  function QuadDobl_Complex_Create
              ( x : C_Double_Array; i : integer32 )
              return QuadDobl_Complex_Numbers.Complex_Number is

  -- DESCRIPTION :
  --   Returns a complex quad double 
  --   with real part in x(i), x(i+1), x(i+2), x(i+3);
  --   and imaginary part in x(i+4), x(i+5), x(i+6), x(i+7).
 
    res_re : constant quad_double := QuadDobl_Create(x,i);
    res_im : constant quad_double := QuadDobl_Create(x,i+4);
    res : constant QuadDobl_Complex_Numbers.Complex_Number
        := QuadDobl_Complex_Numbers.Create(res_re,res_im);

  begin
    return res;
  end QuadDobl_Complex_Create;

  procedure Assign_Double_Double
               ( x : in double_double; i : in integer32;
                 y : out Standard_Floating_Vectors.Vector ) is

  -- DESCRIPTION :
  --   Assigns the high and low part of x to y(i) and y(i+1).

  begin
    y(i) := hi_part(x);
    y(i+1) := lo_part(x);
  end Assign_Double_Double;

  procedure Assign_DoblDobl_Complex
               ( x : in DoblDobl_Complex_Numbers.Complex_Number;
                 i : in integer32;
                 y : out Standard_Floating_Vectors.Vector ) is

  -- DESCRIPTION :
  --   Assigns the high and low part 
  --   of the real part of x to y(i), y(i+1); 
  --   and the high and low part
  --   of the imaginary part of x to y(i+2), y(i+3).

    x_re : constant double_double
         := DoblDobl_Complex_Numbers.REAL_PART(x);
    x_im : constant double_double
         := DoblDobl_Complex_Numbers.IMAG_PART(x);

  begin
    Assign_Double_Double(x_re,i,y);
    Assign_Double_Double(x_im,i+2,y);
  end Assign_DoblDobl_Complex;

  procedure Assign_Quad_Double
               ( x : in quad_double; i : in integer32;
                 y : out Standard_Floating_Vectors.Vector ) is

  -- DESCRIPTION :
  --   Assigns x to y(i), y(i+1), y(i+2), y(i+3).

    x_hi : constant double_double := hi_part(x);
    x_lo : constant double_double := lo_part(x);

  begin
    Assign_Double_Double(x_hi,i,y);
    Assign_Double_Double(x_lo,i+2,y);
  end Assign_Quad_Double;

  procedure Assign_QuadDobl_Complex
               ( x : in QuadDobl_Complex_Numbers.Complex_Number;
                 i : in integer32;
                 y : out Standard_Floating_Vectors.Vector ) is

  -- DESCRIPTION :
  --   Assigns the real part of x to y(i), y(i+1), y(i+2), y(i+3); 
  --   and the imaginary part of x to y(i+4), y(i+5), y(i+6), y(i+7).

    x_re : constant quad_double
         := QuadDobl_Complex_Numbers.REAL_PART(x);
    x_im : constant quad_double
         := QuadDobl_Complex_Numbers.IMAG_PART(x);

  begin
    Assign_Quad_Double(x_re,i,y);
    Assign_Quad_Double(x_im,i+4,y);
  end Assign_QuadDobl_Complex;

-- TARGET FUNCTIONS :

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return Standard_Complex_Solutions.Solution is

    use Standard_Complex_Numbers;

    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(2*nv+5);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    res : Standard_Complex_Solutions.Solution(nv);
    ind : Interfaces.C.size_t := 2;

  begin
    res.t := Create(double_float(sol(0)),double_float(sol(1)));
    res.m := integer32(v(1));
    for i in res.v'range loop
      res.v(i) := Create(double_float(sol(ind)),double_float(sol(ind+1)));
      ind := ind + 2;
    end loop;
    res.err := double_float(sol(Interfaces.C.size_t(2*nv+2)));
    res.rco := double_float(sol(Interfaces.C.size_t(2*nv+3)));
    res.res := double_float(sol(Interfaces.C.size_t(2*nv+4)));
    return res;
  end Convert_to_Solution;

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return DoblDobl_Complex_Solutions.Solution is

    use DoblDobl_Complex_Numbers;

    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(4*nv+10);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    res : DoblDobl_Complex_Solutions.Solution(nv);
    ind : integer32 := 4;

  begin
    res.t := DoblDobl_Complex_Create(sol,0);
    res.m := integer32(v(1));
    for i in res.v'range loop
      res.v(i) := DoblDobl_Complex_Create(sol,ind);
      ind := ind + 4;
    end loop;
    res.err := DoblDobl_Create(sol,ind);
    res.rco := DoblDobl_Create(sol,ind+2);
    res.res := DoblDobl_Create(sol,ind+4);
    return res;
  end Convert_to_Solution;

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return QuadDobl_Complex_Solutions.Solution is

    use QuadDobl_Complex_Numbers;

    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(8*nv+20);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    res : QuadDobl_Complex_Solutions.Solution(nv);
    ind : integer32 := 8;

  begin
    res.t := QuadDobl_Complex_Create(sol,0);
    res.m := integer32(v(1));
    for i in res.v'range loop
      res.v(i) := QuadDobl_Complex_Create(sol,ind);
      ind := ind + 8;
    end loop;
    res.err := QuadDobl_Create(sol,ind);
    res.rco := QuadDobl_Create(sol,ind+4);
    res.res := QuadDobl_Create(sol,ind+8);
    return res;
  end Convert_to_Solution;

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return Standard_Complex_Solutions.Link_to_Solution is

    use Standard_Complex_Numbers;

    res : Standard_Complex_Solutions.Link_to_Solution;
    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(2*nv+5);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    s : Standard_Complex_Solutions.Solution(nv);
    ind : Interfaces.C.size_t := 2;

  begin
    s.t := Create(double_float(sol(0)),double_float(sol(1)));
    s.m := integer32(v(1));
    for i in s.v'range loop
      s.v(i) := Create(double_float(sol(ind)),double_float(sol(ind+1)));
      ind := ind + 2;
    end loop;
    s.err := double_float(sol(Interfaces.C.size_t(2*nv+2)));
    s.rco := double_float(sol(Interfaces.C.size_t(2*nv+3)));
    s.res := double_float(sol(Interfaces.C.size_t(2*nv+4)));
    res := new Standard_Complex_Solutions.Solution'(s);
    return res;
  end Convert_to_Solution;

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return DoblDobl_Complex_Solutions.Link_to_Solution is

    use DoblDobl_Complex_Numbers;

    res : DoblDobl_Complex_Solutions.Link_to_Solution;
    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(4*nv+10);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    s : DoblDobl_Complex_Solutions.Solution(nv);
    ind : integer32 := 4;

  begin
    s.t := DoblDobl_Complex_Create(sol,0);
    s.m := integer32(v(1));
    for i in s.v'range loop
      s.v(i) := DoblDobl_Complex_Create(sol,ind);
      ind := ind + 4;
    end loop;
    s.err := DoblDobl_Create(sol,ind);
    s.rco := DoblDobl_Create(sol,ind+2);
    s.res := DoblDobl_Create(sol,ind+4);
    res := new DoblDobl_Complex_Solutions.Solution'(s);
    return res;
  end Convert_to_Solution;

  function Convert_to_Solution
             ( b : C_intarrs.Pointer; c : C_dblarrs.Pointer )
             return QuadDobl_Complex_Solutions.Link_to_Solution is

    use QuadDobl_Complex_Numbers;

    res : QuadDobl_Complex_Solutions.Link_to_Solution;
    v : constant C_Integer_Array(0..1)
      := C_intarrs.Value(b,Interfaces.C.ptrdiff_t(2));
    nv : constant integer32 := integer32(v(0));
    dim : constant Interfaces.C.size_t := Interfaces.C.size_t(8*nv+20);
    sol : C_Double_Array(0..dim-1)
        := C_dblarrs.Value(c,Interfaces.C.ptrdiff_t(dim));
    s : QuadDobl_Complex_Solutions.Solution(nv);
    ind : integer32 := 8;

  begin
    s.t := QuadDobl_Complex_Create(sol,0);
    s.m := integer32(v(1));
    for i in s.v'range loop
      s.v(i) := QuadDobl_Complex_Create(sol,ind);
      ind := ind + 8;
    end loop;
    s.err := QuadDobl_Create(sol,ind);
    s.rco := QuadDobl_Create(sol,ind+4);
    s.res := QuadDobl_Create(sol,ind+8);
    res := new QuadDobl_Complex_Solutions.Solution'(s);
    return res;
  end Convert_to_Solution;

  procedure Assign_Solution
             ( s : in Standard_Complex_Solutions.Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use Standard_Complex_Numbers;

    dim : constant integer32 := 2*s.n + 5;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 3;

  begin
    sol(1) := REAL_PART(s.t);
    sol(2) := IMAG_PART(s.t);
    Assign(s.m,b);
    for i in s.v'range loop
      sol(ind) := REAL_PART(s.v(i));
      sol(ind+1) := IMAG_PART(s.v(i));
      ind := ind + 2;
    end loop;
    sol(dim-2) := s.err;
    sol(dim-1) := s.rco;
    sol(dim)   := s.res;
    Assign(sol,c);
  end Assign_Solution;

  procedure Assign_Solution
             ( s : in DoblDobl_Complex_Solutions.Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use DoblDobl_Complex_Numbers;

    dim : constant integer32 := 4*s.n + 10;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 5;

  begin
    Assign(s.m,b);
    Assign_DoblDobl_Complex(s.t,1,sol);
    for i in s.v'range loop
      Assign_DoblDobl_Complex(s.v(i),ind,sol);
      ind := ind + 4;
    end loop;
    Assign_Double_Double(s.err,ind,sol);
    Assign_Double_Double(s.rco,ind+2,sol);
    Assign_Double_Double(s.res,ind+4,sol);
    Assign(sol,c);
  end Assign_Solution;

  procedure Assign_Solution
             ( s : in QuadDobl_Complex_Solutions.Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use QuadDobl_Complex_Numbers;

    dim : constant integer32 := 8*s.n + 20;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 9;

  begin
    Assign(s.m,b);
    Assign_QuadDobl_Complex(s.t,1,sol);
    for i in s.v'range loop
      Assign_QuadDobl_Complex(s.v(i),ind,sol);
      ind := ind + 8;
    end loop;
    Assign_Quad_Double(s.err,ind,sol);
    Assign_Quad_Double(s.rco,ind+4,sol);
    Assign_Quad_Double(s.res,ind+8,sol);
    Assign(sol,c);
  end Assign_Solution;

  procedure Assign_Solution
             ( ls : in Standard_Complex_Solutions.Link_to_Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use Standard_Complex_Numbers;

    dim : constant integer32 := 2*ls.n + 5;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 3;

  begin
    sol(1) := REAL_PART(ls.t);
    sol(2) := IMAG_PART(ls.t);
    Assign(ls.m,b);
    for i in ls.v'range loop
      sol(ind) := REAL_PART(ls.v(i));
      sol(ind+1) := IMAG_PART(ls.v(i));
      ind := ind + 2;
    end loop;
    sol(dim-2) := ls.err;
    sol(dim-1) := ls.rco;
    sol(dim)   := ls.res;
    Assign(sol,c);
  end Assign_Solution;

  procedure Assign_Solution
             ( ls : in DoblDobl_Complex_Solutions.Link_to_Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use DoblDobl_Complex_Numbers;

    dim : constant integer32 := 4*ls.n + 10;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 5;

  begin
    Assign(ls.m,b);
    Assign_DoblDobl_Complex(ls.t,1,sol);
    for i in ls.v'range loop
      Assign_DoblDobl_Complex(ls.v(i),ind,sol);
      ind := ind + 4;
    end loop;
    Assign_Double_Double(ls.err,ind,sol);
    Assign_Double_Double(ls.rco,ind+2,sol);
    Assign_Double_Double(ls.res,ind+4,sol);
    Assign(sol,c);
  end Assign_Solution;

  procedure Assign_Solution
             ( ls : in QuadDobl_Complex_Solutions.Link_to_Solution;
               b : in C_intarrs.Pointer; c : in C_dblarrs.Pointer ) is

    use QuadDobl_Complex_Numbers;

    dim : constant integer32 := 8*ls.n + 20;
    sol : Standard_Floating_Vectors.Vector(1..dim);
    ind : integer32 := 9;

  begin
    Assign(ls.m,b);
    Assign_QuadDobl_Complex(ls.t,1,sol);
    for i in ls.v'range loop
      Assign_QuadDobl_Complex(ls.v(i),ind,sol);
      ind := ind + 8;
    end loop;
    Assign_Quad_Double(ls.err,ind,sol);
    Assign_Quad_Double(ls.rco,ind+4,sol);
    Assign_Quad_Double(ls.res,ind+8,sol);
    Assign(sol,c);
  end Assign_Solution;

end Assignments_of_Solutions;