task_url stringlengths 30 116 | task_name stringlengths 2 86 | task_description stringlengths 0 14.4k | language_url stringlengths 2 53 | language_name stringlengths 1 52 | code stringlengths 0 61.9k |
|---|---|---|---|---|---|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Processing | Processing | int a = 7, b = 5;
println(a + " + " + b + " = " + (a + b));
println(a + " - " + b + " = " + (a - b));
println(a + " * " + b + " = " + (a * b));
println(a + " / " + b + " = " + (a / b)); //Rounds towards zero
println(a + " % " + b + " = " + (a % b)); //Same sign as first operand |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #ProDOS | ProDOS | IGNORELINE Note: This example includes the math module.
include arithmeticmodule
:a
editvar /newvar /value=a /title=Enter first integer:
editvar /newvar /value=b /title=Enter second integer:
editvar /newvar /value=c
do add -a-,-b-=-c-
printline -c-
do subtract a,b
printline -c-
do multiply a,b
printline -c-
do divide... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #360_Assembly | 360 Assembly | * Arrays 04/09/2015
ARRAYS PROLOG
* we use TA array with 1 as origin. So TA(1) to TA(20)
* ta(i)=ta(j)
L R1,J j
BCTR R1,0 -1
SLA R1,2 r1=(j-1)*4 (*4 by shift left)
L R0,TA(R1) ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Prolog | Prolog |
print_expression_and_result(M, N, Operator) :-
Expression =.. [Operator, M, N],
Result is Expression,
format('~w ~8|is ~d~n', [Expression, Result]).
arithmetic_integer :-
read(M),
read(N),
maplist( print_expression_and_result(M, N), [+,-,*,//,rem,^] ).
|
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #6502_Assembly | 6502 Assembly | Array:
db 5,10,15,20,25,30,35,40,45,50 |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #PureBasic | PureBasic | OpenConsole()
Define a, b
Print("Number 1: "): a = Val(Input())
Print("Number 2: "): b = Val(Input())
PrintN("Sum: " + Str(a + b))
PrintN("Difference: " + Str(a - b))
PrintN("Product: " + Str(a * b))
PrintN("Quotient: " + Str(a / b)) ; Integer division (rounding mode=truncate)
PrintN("Remainder: " + S... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #68000_Assembly | 68000 Assembly | MOVE.L #$00100000,A0 ;define an array at memory address $100000 |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Python | Python | x = int(raw_input("Number 1: "))
y = int(raw_input("Number 2: "))
print "Sum: %d" % (x + y)
print "Difference: %d" % (x - y)
print "Product: %d" % (x * y)
print "Quotient: %d" % (x / y) # or x // y for newer python versions.
# truncates towards negative infinity
print "Remaind... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #8051_Assembly | 8051 Assembly | ; constant array (elements are unchangeable) - the array is stored in the CODE segment
myarray db 'Array' ; db = define bytes - initializes 5 bytes with values 41, 72, 72, etc. (the ascii characters A,r,r,a,y)
myarray2 dw 'A','r','r','a','y' ; dw = define words - initializes 5 words (1 word = 2 bytes) with values 41 00... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Python_3.x_Long_Form | Python 3.x Long Form | input1 = 18
# input1 = input()
input2 = 7
# input2 = input()
qq = input1 + input2
print("Sum: " + str(qq))
ww = input1 - input2
print("Difference: " + str(ww))
ee = input1 * input2
print("Product: " + str(ee))
rr = input1 / input2
print("Integer quotient: " + str(int(rr)))
print("Float quotient: " + str(f... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #8th | 8th |
[ 1 , 2 ,3 ] \ an array holding three numbers
1 a:@ \ this will be '2', the element at index 1
drop
1 123 a:@ \ this will store the value '123' at index 1, so now
. \ will print [1,123,3]
[1,2,3] 45 a:push
\ gives us [1,2,3,45]
\ and empty spots are filled with null:
[1,2,3] 5 15 a:!
\ gives [1,... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #QB64 | QB64 | START:
INPUT "Enter two integers (a,b):"; a!, b!
IF a = 0 THEN END
IF b = 0 THEN
PRINT "Second integer is zero. Zero not allowed for Quotient or Remainder."
GOTO START
END IF
PRINT
PRINT " Sum = "; a + b
PRINT " Difference = "; a - b
PRINT " Product = "; a * b
' Notice the use of the IN... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #AArch64_Assembly | AArch64 Assembly |
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program areaString64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesA... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Quackery | Quackery | $ "Please enter two integers separated by a space. "
input quackery
2dup say "Their sum is: " + echo cr
2dup say "Their difference is: " - echo cr
2dup say "Their product is: " " * echo cr
2dup say "Their integer quotient is: " / echo cr
2dup say "Their remainder is: ... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ABAP | ABAP |
TYPES: tty_int TYPE STANDARD TABLE OF i
WITH NON-UNIQUE DEFAULT KEY.
DATA(itab) = VALUE tty_int( ( 1 )
( 2 )
( 3 ) ).
INSERT 4 INTO TABLE itab.
APPEND 5 TO itab.
DELETE itab INDEX 1.
cl_demo_output=>display( itab ).
cl_demo_output=>disp... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #R | R | cat("insert number ")
a <- scan(nmax=1, quiet=TRUE)
cat("insert number ")
b <- scan(nmax=1, quiet=TRUE)
print(paste('a+b=', a+b))
print(paste('a-b=', a-b))
print(paste('a*b=', a*b))
print(paste('a%/%b=', a%/%b))
print(paste('a%%b=', a%%b))
print(paste('a^b=', a^b))
|
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ACL2 | ACL2 | ;; Create an array and store it in array-example
(assign array-example
(compress1 'array-example
(list '(:header :dimensions (10)
:maximum-length 11))))
;; Set a[5] to 22
(assign array-example
(aset1 'array-example
(@ array-example)
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Racket | Racket |
#lang racket/base
(define (arithmetic x y)
(for ([op (list + - * / quotient remainder modulo max min gcd lcm)])
(printf "~s => ~s\n" `(,(object-name op) ,x ,y) (op x y))))
(arithmetic 8 12)
|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Raku | Raku | my Int $a = get.floor;
my Int $b = get.floor;
say 'sum: ', $a + $b;
say 'difference: ', $a - $b;
say 'product: ', $a * $b;
say 'integer quotient: ', $a div $b;
say 'remainder: ', $a % $b;
say 'exponentiation: ', $a**$b; |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #Action.21 | Action! | PROC Main()
BYTE i
;array storing 4 INT items with initialized values
;negative values must be written as 16-bit unsigned numbers
INT ARRAY a=[3 5 71 65535]
;array storing 4 CARD items whithout initialization of values
CARD ARRAY b(3)
;array of BYTE items without allocation,
;it may be used as an ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Raven | Raven | ' Number 1: ' print expect 0 prefer as x
' Number 2: ' print expect 0 prefer as y
x y + " sum: %d\n" print
x y - "difference: %d\n" print
x y * " product: %d\n" print
x y / " quotient: %d\n" print
x y % " remainder: %d\n" print |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #REBOL | REBOL | rebol [
Title: "Integer"
URL: http://rosettacode.org/wiki/Arithmetic/Integer
]
x: to-integer ask "Please type in an integer, and press [enter]: "
y: to-integer ask "Please enter another integer: "
print ""
print ["Sum:" x + y]
print ["Difference:" x - y]
print ["Product:" x * y]
print ["Integer quotient (coer... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ActionScript | ActionScript | //creates an array of length 10
var array1:Array = new Array(10);
//creates an array with the values 1, 2
var array2:Array = new Array(1,2);
//arrays can also be set using array literals
var array3:Array = ["foo", "bar"];
//to resize an array, modify the length property
array2.length = 3;
//arrays can contain objects o... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Relation | Relation |
set a = -17
set b = 4
echo "a+b = ".format(a+b,"%1d")
echo "a-b = ".format(a-b,"%1d")
echo "a*b = ".format(a*b,"%1d")
echo "a DIV b = ".format(floor(a/b),"%1d")
echo "a MOD b = ".format(a mod b,"%1d")
echo "a^b = ".format(pow(a,b),"%1d")
|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #ReScript | ReScript | let a = int_of_string(Sys.argv[2])
let b = int_of_string(Sys.argv[3])
let sum = a + b
let difference = a - b
let product = a * b
let division = a / b
let remainder = mod(a, b)
Js.log("a + b = " ++ string_of_int(sum))
Js.log("a - b = " ++ string_of_int(difference))
Js.log("a * b = " ++ string_of_int(product))
Js.log... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #Ada | Ada | procedure Array_Test is
A, B : array (1..20) of Integer;
-- Ada array indices may begin at any value, not just 0 or 1
C : array (-37..20) of integer
-- Ada arrays may be indexed by enumerated types, which are
-- discrete non-numeric types
type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
typ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Retro | Retro | :arithmetic (ab-)
over '\na_______=_%n s:put
dup '\nb_______=_%n s:put
dup-pair + '\na_+_b___=_%n s:put
dup-pair - '\na_-_b___=_%n s:put
dup-pair * '\na_*_b___=_%n s:put
/mod '\na_/_b___=_%n s:put
'\na_mod_b_=_%n\n" s:put ; |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #C | C | #include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_in... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #Aikido | Aikido |
var arr1 = [1,2,3,4] // initialize with array literal
var arr2 = new [10] // empty array of 10 elements (each element has value none)
var arr3 = new int [40] // array of 40 integers
var arr4 = new Object (1,2) [10] // array of 10 instances of Object
arr1.append (5) // add to array
var b = 4 in arr1 // ch... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #REXX | REXX | /*REXX program obtains two integers from the C.L. (a prompt); displays some operations.*/
numeric digits 20 /*#s are round at 20th significant dig.*/
parse arg x y . /*maybe the integers are on the C.L. */
do while \datatype(x,'W') | \datatype(y,'W'... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #C.23 | C# | using System;
using System.Numerics;
class AgmPie
{
static BigInteger IntSqRoot(BigInteger valu, BigInteger guess)
{
BigInteger term; do {
term = valu / guess; if (BigInteger.Abs(term - guess) <= 1) break;
guess += term; guess >>= 1;
} while (true); return guess;
}
... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #Aime | Aime | list l; |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #11l | 11l | V z1 = 1.5 + 3i
V z2 = 1.5 + 1.5i
print(z1 + z2)
print(z1 - z2)
print(z1 * z2)
print(z1 / z2)
print(-z1)
print(conjugate(z1))
print(abs(z1))
print(z1 ^ z2)
print(z1.real)
print(z1.imag) |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Ring | Ring |
func Test a,b
see "a+b" + ( a + b ) + nl
see "a-b" + ( a - b ) + nl
see "a*b" + ( a * b ) + nl
// The quotient isn't integer, so we use the Ceil() function, which truncates it downward.
see "a/b" + Ceil( a / b ) + nl
// Remainder:
see "a%b" + ( a % b ) + nl
see "a**b" + pow(a,b ) + nl
|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Robotic | Robotic |
input string "Enter number 1:"
set "a" to "input"
input string "Enter number 2:"
set "b" to "input"
[ "Sum: ('a' + 'b')"
[ "Difference: ('a' - 'b')"
[ "Product: ('a' * 'b')"
[ "Integer Quotient: ('a' / 'b')"
[ "Remainder: ('a' % 'b')"
[ "Exponentiation: ('a'^'b')"
|
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #C.2B.2B | C++ | #include <gmpxx.h>
#include <chrono>
using namespace std;
using namespace chrono;
void agm(mpf_class& rop1, mpf_class& rop2, const mpf_class& op1,
const mpf_class& op2)
{
rop1 = (op1 + op2) / 2;
rop2 = op1 * op2;
mpf_sqrt(rop2.get_mpf_t(), rop2.get_mpf_t());
}
int main(void)
{
auto st = st... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ALGOL_60 | ALGOL 60 | begin
comment arrays - Algol 60;
procedure static;
begin
integer array x[0:4];
x[0]:=10;
x[1]:=11;
x[2]:=12;
x[3]:=13;
x[4]:=x[0];
outstring(1,"static at 4: ");
outinteger(1,x[4]);
outstring(1,"\n")
end static;
procedure dynamic(n); value n; integer n;
begin
integer... |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #Action.21 | Action! | INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
DEFINE R_="+0"
DEFINE I_="+6"
TYPE Complex=[CARD cr1,cr2,cr3,ci1,ci2,ci3]
BYTE FUNC Positive(REAL POINTER x)
BYTE ARRAY tmp
tmp=x
IF (tmp(0)&$80)=$00 THEN
RETURN (1)
FI
RETURN (0)
PROC PrintComplex(Complex POINTER x)
PrintR(x R_)
IF Positive(x I_)... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Ruby | Ruby | puts 'Enter x and y'
x = gets.to_i # to check errors, use x=Integer(gets)
y = gets.to_i
puts "Sum: #{x+y}",
"Difference: #{x-y}",
"Product: #{x*y}",
"Quotient: #{x/y}", # truncates towards negative infinity
"Quotient: #{x.fdiv(y)}", # float
"Remainder: #{x%y}", # same sign as seco... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Run_BASIC | Run BASIC | input "1st integer: "; i1
input "2nd integer: "; i2
print " Sum"; i1 + i2
print " Diff"; i1 - i2
print " Product"; i1 * i2
if i2 <>0 then print " Quotent "; int( i1 / i2); else print "Cannot divide by zero."
print "Remainder"; i1 MOD i2
print "1st raised to power of 2nd"; i1 ^ i2 |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Clojure | Clojure | (ns async-example.core
(:use [criterium.core])
(:gen-class))
; Java Arbitray Precision Library
(import '(org.apfloat Apfloat ApfloatMath))
(def precision 8192)
; Define big constants (i.e. 1, 2, 4, 0.5, .25, 1/sqrt(2))
(def one (Apfloat. 1M precision))
(def two (Apfloat. 2M precision))
(def four (Apfloat. 4M ... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ALGOL_68 | ALGOL 68 | PROC array_test = VOID:
(
[1:20]INT a;
a := others; # assign whole array #
a[1] := -1; # assign individual element #
a[3:5] := (2, 4, -1); # assign a slice #
[1:3]INT slice = a[3:5]; # copy a slice #
REF []INT rslice = a[3... |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #Ada | Ada | with Ada.Numerics.Generic_Complex_Types;
with Ada.Text_IO.Complex_IO;
procedure Complex_Operations is
-- Ada provides a pre-defined generic package for complex types
-- That package contains definitions for composition,
-- negation, addition, subtraction, multiplication, division,
-- conjugation, exponent... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Rust | Rust | use std::env;
fn main() {
let args: Vec<_> = env::args().collect();
let a = args[1].parse::<i32>().unwrap();
let b = args[2].parse::<i32>().unwrap();
println!("sum: {}", a + b);
println!("difference: {}", a - b);
println!("product: {}", a * b);
println!("integ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Sass.2FSCSS | Sass/SCSS |
@function arithmetic($a,$b) {
@return $a + $b, $a - $b, $a * $b, ($a - ($a % $b))/$b, $a % $b;
}
|
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Common_Lisp | Common Lisp | (load "bf.fasl")
;;(setf mma::bigfloat-bin-prec 1000)
(let ((A (mma:bigfloat-convert 1.0d0))
(N (mma:bigfloat-convert 1.0d0))
(Z (mma:bigfloat-convert 0.25d0))
(G (mma:bigfloat-/ (mma:bigfloat-convert 1.0d0)
(mma:bigfloat-sqrt (mma:bigfloat-convert 2.0d0)))))
(loop repeat 18 do
(... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #D | D | import std.bigint;
import std.conv;
import std.math;
import std.stdio;
BigInt IntSqRoot(BigInt value, BigInt guess) {
BigInt term;
do {
term = value / guess;
auto temp = term - guess;
if (temp < 0) {
temp = -temp;
}
if (temp <= 1) {
break;
... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #ALGOL_W | ALGOL W | begin
% declare an array %
integer array a ( 1 :: 10 );
% set the values %
for i := 1 until 10 do a( i ) := i;
% change the 3rd element %
a( 3 ) := 27;
% display the 4th element %
write( a( 4 ) ); % would show 4 %
% arrays with sizes not known at compile-time must be created in inner... |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #ALGOL_68 | ALGOL 68 | main:(
FORMAT compl fmt = $g(-7,5)"⊥"g(-7,5)$;
PROC compl operations = VOID: (
LONG COMPL a = 1.0 ⊥ 1.0;
LONG COMPL b = 3.14159 ⊥ 1.2;
LONG COMPL c;
printf(($x"a="f(compl fmt)l$,a));
printf(($x"b="f(compl fmt)l$,b));
# addition #
c := a + b;
printf(($x"a+b="f(compl fmt)l$,c))... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Scala | Scala | val a = Console.readInt
val b = Console.readInt
val sum = a + b //integer addition is discouraged in print statements due to confusion with String concatenation
println("a + b = " + sum)
println("a - b = " + (a - b))
println("a * b = " + (a * b))
println("quotient of a / b = " + (a / b)) // truncates towards 0
printl... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Scheme | Scheme | (define (arithmetic x y)
(for-each (lambda (op)
(write (list op x y))
(display " => ")
(write ((eval op) x y))
(newline))
'(+ - * / quotient remainder modulo max min gcd lcm)))
(arithmetic 8 12) |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Delphi | Delphi |
program Calculate_Pi;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Velthuis.BigIntegers,
System.Diagnostics;
function IntSqRoot(value, guess: BigInteger): BigInteger;
var
term: BigInteger;
begin
while True do
begin
term := value div guess;
if (BigInteger.Abs(term - guess) <= 1) then
break;... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #AmigaE | AmigaE | DEF ai[100] : ARRAY OF CHAR, -> static
da: PTR TO CHAR,
la: PTR TO CHAR
PROC main()
da := New(100)
-> or
NEW la[100]
IF da <> NIL
ai[0] := da[0] -> first is 0
ai[99] := da[99] -> last is "size"-1
Dispose(da)
ENDIF
-> using NEW, we must specify the size even when
-> "deallocating"... |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #ALGOL_W | ALGOL W | begin
% show some complex arithmetic %
% returns c + d, using the builtin complex + operator %
complex procedure cAdd ( complex value c, d ) ; c + d;
% returns c * d, using the builtin complex * operator %
complex procedure... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Seed7 | Seed7 | $ include "seed7_05.s7i";
const proc: main is func
local
var integer: a is 0;
var integer: b is 0;
begin
write("a = ");
readln(a);
write("b = ");
readln(b);
writeln("a + b = " <& a + b);
writeln("a - b = " <& a - b);
writeln("a * b = " <& a * b);
writeln("a div b = " <& a... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #SenseTalk | SenseTalk | ask "Enter the first number:"
put it into number1
ask "Enter the second number:"
put it into number2
put "Sum: " & number1 plus number2
put "Difference: " & number1 minus number2
put "Product: " & number1 multiplied by number2
put "Integer quotient: " & number1 div number2 -- Rounding towards 0
put "Remainder: " & ... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Erlang | Erlang |
-module(pi).
-export([agmPi/1, agmPiBody/5]).
agmPi(Loops) ->
% Tail recursive function that produces pi from the Arithmetic Geometric Mean method
A = 1,
B = 1/math:sqrt(2),
J = 1,
Running_divisor = 0.25,
A_n_plus_one = 0.5*(A+B),
B_n_plus_one = math:sqrt(A*B),
Step_difference = A_n_... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #AntLang | AntLang | / Create an immutable sequence (array)
arr: <1;2;3>
/ Get the head an tail part
h: head[arr]
t: tail[arr]
/ Get everything except the last element and the last element
nl: first[arr]
l: last[arr]
/ Get the nth element (index origin = 0)
nth:arr[n] |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #APL | APL |
x←1j1 ⍝assignment
y←5.25j1.5
x+y ⍝addition
6.25J2.5
x×y ⍝multiplication
3.75J6.75
⌹x ⍝inversion
0.5j_0.5
-x ⍝negation
¯1J¯1
|
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #App_Inventor | App Inventor | a: to :complex [1 1]
b: to :complex @[pi 1.2]
print ["a:" a]
print ["b:" b]
print ["a + b:" a + b]
print ["a * b:" a * b]
print ["1 / a:" 1 / a]
print ["neg a:" neg a]
print ["conj a:" conj a] |
http://rosettacode.org/wiki/Arithmetic/Rational | Arithmetic/Rational | Task
Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language.
Example
Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number).
Fur... | #Action.21 | Action! | INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit
TYPE Frac=[INT num,den]
REAL half
PROC PrintFrac(Frac POINTER x)
PrintI(x.num) Put('/) PrintI(x.den)
RETURN
INT FUNC Gcd(INT a,b)
INT tmp
IF a<b THEN
tmp=a a=b b=tmp
FI
WHILE b#0
DO
tmp=a MOD b
a=b
b=tmp
OD
RETURN (a)
PROC Ini... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #11l | 11l | F agm(a0, g0, tolerance = 1e-10)
V an = (a0 + g0) / 2.0
V gn = sqrt(a0 * g0)
L abs(an - gn) > tolerance
(an, gn) = ((an + gn) / 2.0, sqrt(an * gn))
R an
print(agm(1, 1 / sqrt(2))) |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Sidef | Sidef | var a = Sys.scanln("First number: ").to_i;
var b = Sys.scanln("Second number: ").to_i;
%w'+ - * // % ** ^ | & << >>'.each { |op|
"#{a} #{op} #{b} = #{a.$op(b)}".say;
} |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Slate | Slate | [| :a :b |
inform: (a + b) printString.
inform: (a - b) printString.
inform: (a * b) printString.
inform: (a / b) printString.
inform: (a // b) printString.
inform: (a \\ b) printString.
] applyTo: {Integer readFrom: (query: 'Enter a: '). Integer readFrom: (query: 'Enter b: ')}. |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Go | Go | package main
import (
"fmt"
"math/big"
)
func main() {
one := big.NewFloat(1)
two := big.NewFloat(2)
four := big.NewFloat(4)
prec := uint(768) // say
a := big.NewFloat(1).SetPrec(prec)
g := new(big.Float).SetPrec(prec)
// temporary variables
t := new(big.Float).SetPrec(pr... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #Apex | Apex | Integer[] array = new Integer[10]; // optionally, append a braced list of Integers like "{1, 2, 3}"
array[0] = 42;
System.debug(array[0]); // Prints 42 |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #Arturo | Arturo | a: to :complex [1 1]
b: to :complex @[pi 1.2]
print ["a:" a]
print ["b:" b]
print ["a + b:" a + b]
print ["a * b:" a * b]
print ["1 / a:" 1 / a]
print ["neg a:" neg a]
print ["conj a:" conj a] |
http://rosettacode.org/wiki/Arithmetic/Rational | Arithmetic/Rational | Task
Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language.
Example
Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number).
Fur... | #Ada | Ada | generic
type Number is range <>;
package Generic_Rational is
type Rational is private;
function "abs" (A : Rational) return Rational;
function "+" (A : Rational) return Rational;
function "-" (A : Rational) return Rational;
function Inverse (A : Rational) return Rational;
function "+"... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #360_Assembly | 360 Assembly | AGM CSECT
USING AGM,R13
SAVEAREA B STM-SAVEAREA(R15)
DC 17F'0'
DC CL8'AGM'
STM STM R14,R12,12(R13)
ST R13,4(R15)
ST R15,8(R13)
LR R13,R15
ZAP A,K a=1
ZAP PWL8,K
MP PWL8,K
... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #8th | 8th | : epsilon 1.0e-12 ;
with: n
: iter \ n1 n2 -- n1 n2
2dup * sqrt >r + 2 / r> ;
: agn \ n1 n2 -- n
repeat iter 2dup epsilon ~= not while! drop ;
"agn(1, 1/sqrt(2)) = " . 1 1 2 sqrt / agn "%.10f" s:strfmt . cr
;with
bye
|
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #Smalltalk | Smalltalk | | a b |
'Input number a: ' display.
a := (stdin nextLine) asInteger.
'Input number b: ' display.
b := (stdin nextLine) asInteger.
('a+b=%1' % { a + b }) displayNl.
('a-b=%1' % { a - b }) displayNl.
('a*b=%1' % { a * b }) displayNl.
('a/b=%1' % { a // b }) displayNl.
('a%%b=%1' % { a \\ b }) displayNl. |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Groovy | Groovy | import java.math.MathContext
class CalculatePi {
private static final MathContext con1024 = new MathContext(1024)
private static final BigDecimal bigTwo = new BigDecimal(2)
private static final BigDecimal bigFour = new BigDecimal(4)
private static BigDecimal bigSqrt(BigDecimal bd, MathContext con) {... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #APL | APL | +/ 1 2 3 |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #AutoHotkey | AutoHotkey | Cset(C,1,1)
MsgBox % Cstr(C) ; 1 + i*1
Cneg(C,C)
MsgBox % Cstr(C) ; -1 - i*1
Cadd(C,C,C)
MsgBox % Cstr(C) ; -2 - i*2
Cinv(D,C)
MsgBox % Cstr(D) ; -0.25 + 0.25*i
Cmul(C,C,D)
MsgBox % Cstr(C) ; 1 + i*0
Cset(ByRef C, re, im) {
VarSetCapacity(C,16)
NumPut(re,C,0,"double")
NumPut(im,C,8,"double")
}
Cre(ByRef... |
http://rosettacode.org/wiki/Arena_storage_pool | Arena storage pool | Dynamically allocated objects take their memory from a heap.
The memory for an object is provided by an allocator which maintains the storage pool used for the heap.
Often a call to allocator is denoted as
P := new T
where T is the type of an allocated object, and P is a reference to the object.
The stora... | #Ada | Ada | type My_Pointer is access My_Object;
for My_Pointer'Storage_Pool use My_Pool; |
http://rosettacode.org/wiki/Arithmetic/Rational | Arithmetic/Rational | Task
Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language.
Example
Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number).
Fur... | #ALGOL_68 | ALGOL 68 | MODE FRAC = STRUCT( INT num #erator#, den #ominator#);
FORMAT frac repr = $g(-0)"//"g(-0)$;
PROC gcd = (INT a, b) INT: # greatest common divisor #
(a = 0 | b |: b = 0 | a |: ABS a > ABS b | gcd(b, a MOD b) | gcd(a, b MOD a));
PROC lcm = (INT a, b)INT: # least common multiple #
a OVER gcd(a, b) * b;
P... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #Action.21 | Action! | INCLUDE "H6:REALMATH.ACT"
PROC Agm(REAL POINTER a0,g0,result)
REAL a,g,prevA,tmp,r2
RealAssign(a0,a)
RealAssign(g0,g)
IntToReal(2,r2)
DO
RealAssign(a,prevA)
RealAdd(a,g,tmp)
RealDiv(tmp,r2,a)
RealMult(prevA,g,tmp)
Sqrt(tmp,g)
IF RealGreaterOrEqual(a,prevA) THEN
EXIT
FI
... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #Ada | Ada | with Ada.Text_IO, Ada.Numerics.Generic_Elementary_Functions;
procedure Arith_Geom_Mean is
type Num is digits 18; -- the largest value gnat/gcc allows
package N_IO is new Ada.Text_IO.Float_IO(Num);
package Math is new Ada.Numerics.Generic_Elementary_Functions(Num);
function AGM(A, G: Num) return Num is... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #smart_BASIC | smart BASIC | INPUT "Enter first number.":first
INPUT "Enter second number.":second
PRINT "The sum of";first;"and";second;"is ";first+second&"."
PRINT "The difference between";first;"and";second;"is ";ABS(first-second)&"."
PRINT "The product of";first;"and";second;"is ";first*second&"."
IF second THEN
PRINT "The integer quotient... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Haskell | Haskell | import Prelude hiding (pi)
import Data.Number.MPFR hiding (sqrt, pi, div)
import Data.Number.MPFR.Instances.Near ()
-- A generous overshoot of the number of bits needed for a
-- given number of digits.
digitBits :: (Integral a, Num a) => a -> a
digitBits n = (n + 1) `div` 2 * 8
-- Calculate pi accurate to a given n... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #App_Inventor | App Inventor | set empty to {}
set ints to {1, 2, 3} |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #AWK | AWK | # simulate a struct using associative arrays
function complex(arr, re, im) {
arr["re"] = re
arr["im"] = im
}
function re(cmplx) {
return cmplx["re"]
}
function im(cmplx) {
return cmplx["im"]
}
function printComplex(cmplx) {
print re(cmplx), im(cmplx)
}
function abs2(cmplx) {
return re(cm... |
http://rosettacode.org/wiki/Arena_storage_pool | Arena storage pool | Dynamically allocated objects take their memory from a heap.
The memory for an object is provided by an allocator which maintains the storage pool used for the heap.
Often a call to allocator is denoted as
P := new T
where T is the type of an allocated object, and P is a reference to the object.
The stora... | #C | C | #include <stdlib.h> |
http://rosettacode.org/wiki/Arena_storage_pool | Arena storage pool | Dynamically allocated objects take their memory from a heap.
The memory for an object is provided by an allocator which maintains the storage pool used for the heap.
Often a call to allocator is denoted as
P := new T
where T is the type of an allocated object, and P is a reference to the object.
The stora... | #C.2B.2B | C++ | T* foo = new(arena) T; |
http://rosettacode.org/wiki/Arena_storage_pool | Arena storage pool | Dynamically allocated objects take their memory from a heap.
The memory for an object is provided by an allocator which maintains the storage pool used for the heap.
Often a call to allocator is denoted as
P := new T
where T is the type of an allocated object, and P is a reference to the object.
The stora... | #Delphi | Delphi |
program Arena_storage_pool;
{$APPTYPE CONSOLE}
uses
Winapi.Windows,
System.SysUtils,
system.generics.collections;
type
TPool = class
private
FStorage: TList<Pointer>;
public
constructor Create;
destructor Destroy; override;
function Allocate(aSize: Integer): Pointer;
function Rel... |
http://rosettacode.org/wiki/Arithmetic/Rational | Arithmetic/Rational | Task
Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language.
Example
Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number).
Fur... | #Arturo | Arturo | a: to :rational [1 2]
b: to :rational [3 4]
print ["a:" a]
print ["b:" b]
print ["a + b :" a + b]
print ["a - b :" a - b]
print ["a * b :" a * b]
print ["a / b :" a / b]
print ["a // b :" a // b]
print ["a % b :" a % b]
print ["reciprocal b:" reciprocal b]
print ["neg a:" neg a]
print ["pi ~=" to :rational... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #ALGOL_68 | ALGOL 68 |
BEGIN
PROC agm = (LONG REAL x, y) LONG REAL :
BEGIN
IF x < LONG 0.0 OR y < LONG 0.0 THEN -LONG 1.0
ELIF x + y = LONG 0.0 THEN LONG 0.0 CO Edge cases CO
ELSE
LONG REAL a := x, g := y;
LONG REAL epsilon := a + g;
LONG REAL next a := (a + g) / LONG 2.0, next g := long sqrt (a * g);
LONG ... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #SNOBOL4 | SNOBOL4 |
output = "Enter first integer:"
first = input
output = "Enter second integer:"
second = input
output = "sum = " first + second
output = "diff = " first - second
output = "prod = " first * second
output = "quot = " (qout = first / second)
output = "rem = " first - (qout * second)
output = "expo =... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #SNUSP | SNUSP | $\
,
@
\=@@@-@-----# atoi
>
,
@
\=@@@-@-----#
<
@ # 4 copies
\=!/?!/->>+>>+>>+>>+<<<<<<<<?\#
> | #\?<<<<<<<<+>>+>>+>>+>>-/
@ |
\==/
\>>>>\
/>>>>/
@
\==!/===?\# add
< \>+<-/
@
\=@@@+@+++++# itoa
.
<
@
\==!/===?\# subtract
< \>-<-/
@
\=@@@+@+++++#
.
!
/\
?- ... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #J | J | DP=: 100
round=: DP&$: : (4 : 0)
b %~ <.1r2+y*b=. 10x^x
)
sqrt=: DP&$: : (4 : 0) " 0
assert. 0<:y
%/ <.@%: (2 x: (2*x) round y)*10x^2*x+0>.>.10^.y
)
pi =: 3 : 0
A =. N =. 1x
'G Z HALF' =. (% sqrt 2) , 1r4 1r2
for_I. i.18 do.
X =. ((A + G) * HALF) , sqrt A * G
VAR =. ({.X) - A
Z =. Z - VAR * VAR * N
... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Java | Java | import java.math.BigDecimal;
import java.math.MathContext;
import java.util.Objects;
public class Calculate_Pi {
private static final MathContext con1024 = new MathContext(1024);
private static final BigDecimal bigTwo = new BigDecimal(2);
private static final BigDecimal bigFour = new BigDecimal(4);
... |
http://rosettacode.org/wiki/Arrays | Arrays | This task is about arrays.
For hashes or associative arrays, please see Creating an Associative Array.
For a definition and in-depth discussion of what an array is, see Array.
Task
Show basic array syntax in your language.
Basically, create an array, assign a value to it, and retrieve an element (if available,... | #AppleScript | AppleScript | set empty to {}
set ints to {1, 2, 3} |
http://rosettacode.org/wiki/Arithmetic/Complex | Arithmetic/Complex | A complex number is a number which can be written as:
a
+
b
×
i
{\displaystyle a+b\times i}
(sometimes shown as:
b
+
a
×
i
{\displaystyle b+a\times i}
where
a
{\displaystyle a}
and
b
{\displaystyle b}
are real numbers, and
i
{\displaystyle i}
is √ -1
Typica... | #BASIC | BASIC | TYPE complex
real AS DOUBLE
imag AS DOUBLE
END TYPE
DECLARE SUB suma (a AS complex, b AS complex, c AS complex)
DECLARE SUB rest (a AS complex, b AS complex, c AS complex)
DECLARE SUB mult (a AS complex, b AS complex, c AS complex)
DECLARE SUB divi (a AS complex, b AS complex, c AS complex)
DECLARE SU... |
http://rosettacode.org/wiki/Arena_storage_pool | Arena storage pool | Dynamically allocated objects take their memory from a heap.
The memory for an object is provided by an allocator which maintains the storage pool used for the heap.
Often a call to allocator is denoted as
P := new T
where T is the type of an allocated object, and P is a reference to the object.
The stora... | #Erlang | Erlang |
-module( arena_storage_pool ).
-export( [task/0] ).
task() ->
Pid = erlang:spawn_opt( fun() -> loop([]) end, [{min_heap_size, 10000}] ),
set( Pid, 1, ett ),
set( Pid, "kalle", "hobbe" ),
V1 = get( Pid, 1 ),
V2 = get( Pid, "kalle" ),
true = (V1 =:= ett) and (V2 =:= "hobbe"),
... |
http://rosettacode.org/wiki/Arithmetic/Rational | Arithmetic/Rational | Task
Create a reasonably complete implementation of rational arithmetic in the particular language using the idioms of the language.
Example
Define a new type called frac with binary operator "//" of two integers that returns a structure made up of the numerator and the denominator (as per a rational number).
Fur... | #BBC_BASIC | BBC BASIC | *FLOAT64
DIM frac{num, den}
DIM Sum{} = frac{}, Kf{} = frac{}, One{} = frac{}
One.num = 1 : One.den = 1
FOR n% = 2 TO 2^19-1
Sum.num = 1 : Sum.den = n%
FOR k% = 2 TO SQR(n%)
IF (n% MOD k%) = 0 THEN
Kf.num = 1 : Kf.den = k%
PROCadd(Sum{}, ... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #APL | APL |
agd←{(⍺-⍵)<10*¯8:⍺⋄((⍺+⍵)÷2)∇(⍺×⍵)*÷2}
1 agd ÷2*÷2
|
http://rosettacode.org/wiki/Arithmetic-geometric_mean | Arithmetic-geometric mean |
This page uses content from Wikipedia. The original article was at Arithmetic-geometric mean. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)
Task
Write a function to compute the arithmetic-geomet... | #AppleScript | AppleScript | -- ARITHMETIC GEOMETRIC MEAN -------------------------------------------------
property tolerance : 1.0E-5
-- agm :: Num a => a -> a -> a
on agm(a, g)
script withinTolerance
on |λ|(m)
tell m to ((its an) - (its gn)) < tolerance
end |λ|
end script
script nextRefinement
... |
http://rosettacode.org/wiki/Arithmetic/Integer | Arithmetic/Integer |
Basic Data Operation
This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:
Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |... | #SQL | SQL |
-- test.sql
-- Tested in SQL*plus
DROP TABLE test;
CREATE TABLE test (a INTEGER, b INTEGER);
INSERT INTO test VALUES ('&&A','&&B');
commit;
SELECT a-b difference FROM test;
SELECT a*b product FROM test;
SELECT trunc(a/b) integer_quotient FROM test;
SELECT MOD(a,b) remainder FROM test;
SELECT POWER... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #jq | jq | # include "rational"; # a reminder
def pi(precision):
(precision | (. + log) | ceil) as $digits
| def sq: . as $in | rmult($in; $in) | rround($digits);
{an: r(1;1),
bn: (r(1;2) | rsqrt($digits)),
tn: r(1;4),
pn: 1 }
| until (.pn > $digits;
.an as $prevAn
| .an = (rmult(radd(.bn; .an); r(... |
http://rosettacode.org/wiki/Arithmetic-geometric_mean/Calculate_Pi | Arithmetic-geometric mean/Calculate Pi | Almkvist Berndt 1988 begins with an investigation of why the agm is such an efficient algorithm, and proves that it converges quadratically. This is an efficient method to calculate
π
{\displaystyle \pi }
.
With the same notations used in Arithmetic-geometric mean, we can summarize the paper by writing:
π
... | #Julia | Julia | using Printf
agm1step(x, y) = (x + y) / 2, sqrt(x * y)
function approxπstep(x, y, z, n::Integer)
a, g = agm1step(x, y)
k = n + 1
s = z + 2 ^ (k + 1) * (a ^ 2 - g ^ 2)
return a, g, s, k
end
approxπ(a, g, s) = 4a ^ 2 / (1 - s)
function testmakepi()
setprecision(512)
a, g, s, k = BigFloat(1.0), 1... |
Subsets and Splits
Rosetta Code Task Comparisons
Identifies tasks common to both COBOL and Python languages that are described as having difficulty levels, revealing cross-language task similarities and providing useful comparative programming examples.
Select Specific Languages Codes
Retrieves specific programming language names and codes from training data, providing basic filtering but limited analytical value beyond identifying these particular languages.