Data update

This commit is contained in:
Ingy döt Net 2025-08-11 18:05:26 -07:00
parent 4d5544505c
commit 4924dd0264
3073 changed files with 55820 additions and 4408 deletions

View file

@ -0,0 +1,10 @@
(let a 4)
(let b 5)
(assert (= (+ a b) 9) "sum")
(assert (= (- a b) -1) "difference")
(assert (= (- b a) 1) "difference")
(assert (= (* a b) 20) "product")
(assert (= (/ a b) 0.8) "quotient")
(assert (= (mod a b) 4) "remainder(a, b)")
(assert (= (mod b a) 1) "remainder(b, a)")

View file

@ -0,0 +1,3 @@
SELECT x, y, (x+y), (x-y), (x*y), x // y, mod(x,y), exp(x)
FROM read_csv_auto('rc-arithmetic-integer.txt', header=false,
columns={'x': 'HUGEINT', 'y': 'HUGEINT'}) ;

View file

@ -3,13 +3,13 @@ import extensions;
public program()
{
var a := console.loadLineTo(new Integer());
var b := console.loadLineTo(new Integer());
var a := Console.loadLineTo(new Integer());
var b := Console.loadLineTo(new Integer());
console.printLine(a," + ",b," = ",a + b);
console.printLine(a," - ",b," = ",a - b);
console.printLine(a," * ",b," = ",a * b);
console.printLine(a," / ",b," = ",a / b); // truncates towards 0
console.printLine(a," % ",b," = ",a.mod(b)); // matches sign of first operand
console.printLine(a," ^ ",b," = ",a ^ b);
Console.printLine(a," + ",b," = ",a + b);
Console.printLine(a," - ",b," = ",a - b);
Console.printLine(a," * ",b," = ",a * b);
Console.printLine(a," / ",b," = ",a / b); // truncates towards 0
Console.printLine(a," % ",b," = ",a.mod(b)); // matches sign of first operand
Console.printLine(a," ^ ",b," = ",a ^ b);
}

View file

@ -1,13 +1,16 @@
class BasicIntegerArithmetic {
public static function main() {
var args =Sys.args();
if (args.length < 2) return;
var a = Std.parseFloat(args[0]);
var b = Std.parseFloat(args[1]);
trace("a+b = " + (a+b));
trace("a-b = " + (a-b));
trace("a*b = " + (a*b));
trace("a/b = " + (a/b));
trace("a%b = " + (a%b));
class Main {
static public function main():Void {
var input_a = Sys.stdin().readLine();
var input_b = Sys.stdin().readLine();
var a = Std.parseInt(input_a);
var b = Std.parseInt(input_b);
trace(a + b);
trace(a - b);
trace(a * b);
trace(Std.int(a / b));
trace(a % b);
trace(Math.pow(a, b));
}
}

View file

@ -1,5 +1,7 @@
program arithmetic(input, output)
{$IFDEF FPC}
uses math;
{$ENDIF}
var
a, b: integer;

View file

@ -0,0 +1,13 @@
local function divmod(a, b) return { a // b, a % b } end
io.write("Input the first integer : ")
local a = io.read("n")
io.write("Input the second integer: ")
local b = io.read("n")
print($"sum: {a + b}")
print($"difference {a - b}")
print($"product {a * b}")
print($"quotient {a // b}")
print($"remainder {a % b}")
print($"exponentation {math.tointeger(a ^ b)}")
print($"divmod {divmod(a, b):concat(", ")}")

View file

@ -0,0 +1,146 @@
# riscv assembly raspberry pico2 rp2350
# program arith.s
# connexion putty com3
/*********************************************/
/* CONSTANTES */
/********************************************/
/* for this file see risc-v task include a file */
.include "../../constantesRiscv.inc"
/*******************************************/
/* INITIALED DATAS */
/*******************************************/
.data
szMessStart: .asciz "Program riscv start.\r\n"
szCariageReturn: .asciz "\r\n"
szMessAdd: .asciz "Addition result :\r\n"
szMessSub: .asciz "Substraction result :\r\n"
szMessMul: .asciz "Multiplication result :\r\n"
szMessDiv: .asciz "Division result :\r\n"
szMessRem: .asciz "Division remainder :\r\n"
.align 2
#tabValues: .int 1,2,3,4
/*******************************************/
/* UNINITIALED DATA */
/*******************************************/
.bss
.align 2
sConvArea: .skip 24
/**********************************************/
/* SECTION CODE */
/**********************************************/
.text
.global main
main:
call stdio_init_all # général init
1: # start loop connexion
li a0,0 # raz argument register
call tud_cdc_n_connected # waiting for USB connection
beqz a0,1b # return code = zero ?
la a0,szMessStart # message address
call writeString # display message
la a0,szMessAdd # addition
call writeString # display message
li t0,10
addi a0,t0,1 # add immediat number
call displayResult
li s0,15
li s1,8
add a0,s0,s1 # register add
call displayResult
la a0,szMessSub # subtraction
call writeString # display message
addi a0,s0,-6 # substract immediat number
call displayResult
sub a0,s0,s1 # substract register s1 to s0
call displayResult
la a0,szMessMul # multiplication
call writeString # display message
mul a0,s0,s1 # multiplication register
call displayResult
li s0,12345678
li s1,23456789
mul a0,s0,s1 # multiplication register
call displayResult
mulh a0,s0,s1 # Multiply signed (32) by signed (32), return upper 32 bits of the 64-bit result.
call displayResult
mulhsu a0,s0,s1 # Multiply signed (32) by unsigned (32), return upper 32 bits of the 64-bit result.
call displayResult
mulhu a0,s0,s1 # Multiply unsigned (32) by unsigned (32), return upper 32 bits of the 64-bit result.
call displayResult
la a0,szMessDiv # division
call writeString # display message
li s0,-25
li s1,8
div a0,s0,s1 # divide signed
call displayResultS
li s0,-25
li s1,8
divu a0,s0,s1 # Divide (unsigned)
call displayResult
la a0,szMessRem # division
call writeString # display message
li s0,-10
li s1,8
rem a0,s0,s1 # Remainder (signed).
call displayResultS
li s0,-10
li s1,8
remu a0,s0,s1 # Remainder (unsigned).
call displayResult
call getchar
100: # final loop
j 100b
/**********************************************/
/* display result unsigned */
/**********************************************/
/* a0 value */
.equ LGZONECONV, 20
displayResult:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp)
la a1,sConvArea # conversion result address
call conversion10 # conversion decimal
la a0,sConvArea # message address
call writeString # display message
la a0,szCariageReturn
call writeString
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/**********************************************/
/* displayResult signed */
/**********************************************/
/* a0 value */
.equ LGZONECONV, 20
displayResultS:
addi sp, sp, -4 # reserve stack
sw ra, 0(sp)
la a1,sConvArea # conversion result address
call conversion10S # conversion decimal
la a0,sConvArea # message address
call writeString # display message
la a0,szCariageReturn
call writeString
100:
lw ra, 0(sp)
addi sp, sp, 4
ret
/************************************/
/* file include Fonctions */
/***********************************/
/* for this file see risc-v task include a file */
.include "../../includeFunctions.s"

View file

@ -0,0 +1,42 @@
Red [ "Arithmetic / Integers" ]
;-- Modulo and // in Red are Euclidean modulo, so the correct integer (Euclidean) division must satisfy:
; a = b * div(a,b) + mod(a,b)
; with 0 <= mod(a,b) < |b|
; This is a custom operator to accompany the built-in Euclidean modulo
ediv: make op! function [a b] [
either b > 0
[ to-integer round/floor a / b ] ;b > 0: floor toward -inf
[ to-integer round/ceiling a / b ] ;b < 0: ceiling toward +inf
]
; Python-style divmod:
edivmod: make op! function [a b] [ compose [(a ediv b) (a // b)] ]
;-- C-style truncated integer division:
quot: make op! function [a b] [ to-integer a / b ] ;truncated toward zero
; Haskell-style quotrem:
quotrem: make op! function [a b] [ compose [(a quot b) (a % b)] ]; reduce [a quot b a % b] ] ; rounds -> 0
while [(s: ask "^/Enter two integer separated with space (q = quit): ") <> "q"] [
s: load rejoin ["[" s "]"] a: s/1 b: s/2
print ["Sum :" a "+" b " = " a + b]
print ["Difference :" a "-" b " = " a - b]
print ["Product :" a "*" b " = " a * b]
print "^/Red's Euclidean Division:"
print ["eDiv :" a "eDiv " b " = " a eDiv b]
print ["modulo : modulo" a b " = " modulo a b] ;non-negative
print ["// :" a "//" b " = " a // b] ;operator form
print ["eDivMod :" a "eDivMod" b "= " mold a eDivMod b]
print rejoin ["Check: ("a" eDiv " b") * "b" + ("a" // "b") = "a" ? " (a eDiv b) * b + (a // b) = a]
print "^/Red's C-style truncated integer division:"
print ["quot :" a "quot" b " = " a quot b]
print ["remainder : remainder" a b " = " remainder a b] ;sign as dividend
print ["% :" a "%" b " = " a % b] ;operator form
print ["quotRem :" a "quotRem" b " = " mold a quotRem b]
print rejoin ["Check: ("a" quot " b") * "b" + ("a" % "b") = "a" ? " (a quot b) * b + (a % b) = a]
print ["^/Exponentiation :" a "**" b " = " a ** b]
]

View file

@ -0,0 +1,11 @@
a, b =: 6, 4
print 'a + b =', a + b
print 'a - b =', a - b
print 'a * b =', a * b
print 'a // b =', a // b \ integer division is %%
print 'a %% b =', a %% b \ usual modulus
print 'a ^ b =', a ^ b
qr =: a // b, a %% b \ operator /% rarely used, not implemented
print 'a /% b =', join qr by ','
r =: a / b \ rational result
print r, r.num, r.den \ number, numerator, denominator

View file

@ -1,23 +1,26 @@
const std = @import("std");
pub fn main() !void {
var buf: [1024]u8 = undefined;
const reader = std.io.getStdIn().reader();
const stdout = std.io.getStdOut().writer();
try stdout.writeAll("Enter two integers separated by a space: ");
const input = try reader.readUntilDelimiter(&buf, '\n');
const text = std.mem.trimRight(u8, input, "\r\n");
const stdin = std.io.getStdIn().reader();
var buff = [_]u8{0} ** 1024;
var it = std.mem.tokenizeScalar(u8, text, ' ');
try stdout.print("Value of a: ", .{});
const input_a: ?[]u8 = try stdin.readUntilDelimiterOrEof(buff[0..], '\n');
const trimmed_a = std.mem.trimEnd(u8, input_a.?, "\r"); // for Windows
const a = try std.fmt.parseInt(i32, trimmed_a, 10);
const a = try std.fmt.parseInt(i64, it.next().?, 10);
const b = try std.fmt.parseInt(i64, it.next().?, 10);
try stdout.print("Value of b: ", .{});
const input_b: ?[]u8 = try stdin.readUntilDelimiterOrEof(buff[0..], '\n');
const trimmed_b = std.mem.trimEnd(u8, input_b.?, "\r"); // for Windows
const b = try std.fmt.parseInt(i32, trimmed_b, 10);
try stdout.print("Values: a {d} b {d}\n", .{a, b});
try stdout.print("Sum: a + b = {d}\n", .{a + b});
try stdout.print("Difference: a - b = {d}\n", .{a - b});
try stdout.print("Product: a * b = {d}\n", .{a * b});
try stdout.print("Integer quotient: a / b = {d}\n", .{@divTrunc(a, b)}); //truncates towards 0
try stdout.print("Remainder: a % b = {d}\n", .{@rem(a, b)}); // same sign as first operand
try stdout.print("Exponentiation: math.pow = {d}\n", .{std.math.pow(i64, a, b)}); //no exponentiation operator
try stdout.print("a + b = {d}\n", .{a + b});
try stdout.print("a - b = {d}\n", .{a - b});
try stdout.print("a * b = {d}\n", .{a * b});
try stdout.print("a / b (floor) = {d}\n", .{@divFloor(a, b)});
try stdout.print("a / b (trunk) = {d}\n", .{@divTrunc(a, b)});
try stdout.print("a % b (mod) = {d}\n", .{@mod(a, b)});
try stdout.print("a % b (rem) = {d}\n", .{@rem(a, b)});
try stdout.print("a ^ b = {d}\n", .{std.math.pow(i32, a, b)});
}