Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

21
LINES

< > BotCompany Repo | #1033054 // doubleAdd

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3882L/22K).

1  
// add constant to each element
2  
static double[] doubleAdd(double[] l, double a) {
3  
  if (a == 0) ret l;
4  
  int n = l(l);
5  
  double[] x = new[n];
6  
  for i to n:
7  
    x[i] = l[i]+a;
8  
  ret x;
9  
}
10  
11  
// add element-wise
12  
static double[] doubleAdd(double[] a, double[] b) {
13  
  if (a == null) ret b;
14  
  if (b == null) ret a;
15  
  int n = l(a);
16  
  assertEquals(l(b), n);
17  
  double[] x = new[n];
18  
  for i to n:
19  
    x[i] = a[i]+b[i];
20  
  ret x;
21  
}

Author comment

Began life as a copy of #1033042

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033054
Snippet name: doubleAdd
Eternal ID of this version: #1033054/4
Text MD5: 587d13c33a46df81f2609a254ab37b2c
Transpilation MD5: 07bd45c3b492bb0fd1385252e846eaf5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-18 02:31:25
Source code size: 437 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 202 / 297
Version history: 3 change(s)
Referenced in: [show references]