This commit is contained in:
gingerBill
2022-09-22 00:05:46 +01:00
34 changed files with 198 additions and 54 deletions
+2 -2
View File
@@ -49,8 +49,8 @@ foreign libc {
// 7.3.8 Power and absolute-value functions // 7.3.8 Power and absolute-value functions
cabs :: proc(z: complex_double) -> complex_double --- cabs :: proc(z: complex_double) -> complex_double ---
cabsf :: proc(z: complex_float) -> complex_float --- cabsf :: proc(z: complex_float) -> complex_float ---
cpow :: proc(z: complex_double) -> complex_double --- cpow :: proc(x, y: complex_double) -> complex_double ---
cpowf :: proc(z: complex_float) -> complex_float --- cpowf :: proc(x, y: complex_float) -> complex_float ---
csqrt :: proc(z: complex_double) -> complex_double --- csqrt :: proc(z: complex_double) -> complex_double ---
csqrtf :: proc(z: complex_float) -> complex_float --- csqrtf :: proc(z: complex_float) -> complex_float ---
+1 -1
View File
@@ -120,7 +120,7 @@ read_entire_file_from_handle :: proc(fd: Handle, allocator := context.allocator)
data = make([]byte, int(length), allocator) data = make([]byte, int(length), allocator)
if data == nil { if data == nil {
return nil, false return nil, false
} }
bytes_read, read_err := read_full(fd, data) bytes_read, read_err := read_full(fd, data)
+23 -20
View File
@@ -1,27 +1,27 @@
package all package all
import botan "vendor:botan" import botan "vendor:botan"
import ENet "vendor:ENet" import ENet "vendor:ENet"
import ggpo "vendor:ggpo" import ggpo "vendor:ggpo"
import gl "vendor:OpenGL" import gl "vendor:OpenGL"
import glfw "vendor:glfw" import glfw "vendor:glfw"
import microui "vendor:microui" import microui "vendor:microui"
import miniaudio "vendor:miniaudio" import miniaudio "vendor:miniaudio"
import PM "vendor:portmidi" import PM "vendor:portmidi"
import rl "vendor:raylib" import rl "vendor:raylib"
import exr "vendor:OpenEXRCore" import exr "vendor:OpenEXRCore"
import SDL "vendor:sdl2" import SDL "vendor:sdl2"
import SDLNet "vendor:sdl2/net" import SDLNet "vendor:sdl2/net"
import IMG "vendor:sdl2/image" import IMG "vendor:sdl2/image"
import MIX "vendor:sdl2/mixer" import MIX "vendor:sdl2/mixer"
import TTF "vendor:sdl2/ttf" import TTF "vendor:sdl2/ttf"
import vk "vendor:vulkan" import vk "vendor:vulkan"
import NS "vendor:darwin/Foundation" import NS "vendor:darwin/Foundation"
import MTL "vendor:darwin/Metal" import MTL "vendor:darwin/Metal"
import CA "vendor:darwin/QuartzCore" import CA "vendor:darwin/QuartzCore"
_ :: botan _ :: botan
_ :: ENet _ :: ENet
@@ -33,12 +33,15 @@ _ :: miniaudio
_ :: PM _ :: PM
_ :: rl _ :: rl
_ :: exr _ :: exr
_ :: SDL _ :: SDL
_ :: SDLNet _ :: SDLNet
_ :: IMG _ :: IMG
_ :: MIX _ :: MIX
_ :: TTF _ :: TTF
_ :: vk _ :: vk
_ :: NS _ :: NS
_ :: MTL _ :: MTL
_ :: CA _ :: CA
+5
View File
@@ -0,0 +1,5 @@
//+build windows, linux
package all
import cm "vendor:commonmark"
_ :: cm
+5
View File
@@ -0,0 +1,5 @@
//+build windows, linux
package all
import zlib "vendor:zlib"
_ :: zlib
+5 -2
View File
@@ -2,7 +2,7 @@ ODIN=../../odin
PYTHON=$(shell which python3) PYTHON=$(shell which python3)
all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test encoding_test \ all: download_test_assets image_test compress_test strings_test hash_test crypto_test noise_test encoding_test \
math_test linalg_glsl_math_test filepath_test reflect_test os_exit_test i18n_test math_test linalg_glsl_math_test filepath_test reflect_test os_exit_test i18n_test c_libc_test
download_test_assets: download_test_assets:
$(PYTHON) download_assets.py $(PYTHON) download_assets.py
@@ -47,4 +47,7 @@ os_exit_test:
$(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0 $(ODIN) run os/test_core_os_exit.odin -file -out:test_core_os_exit && exit 1 || exit 0
i18n_test: i18n_test:
$(ODIN) run text/i18n -out:test_core_i18n $(ODIN) run text/i18n -out:test_core_i18n
c_libc_test:
$(ODIN) run c/libc -out:test_core_libc
+37
View File
@@ -0,0 +1,37 @@
package test_core_libc
import "core:fmt"
import "core:os"
import "core:strings"
import "core:testing"
TEST_count := 0
TEST_fail := 0
when ODIN_TEST {
expect :: testing.expect
log :: testing.log
} else {
expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
TEST_count += 1
if !condition {
TEST_fail += 1
fmt.printf("[%v] %v\n", loc, message)
return
}
}
log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
fmt.printf("[%v] ", loc)
fmt.printf("log: %v\n", v)
}
}
main :: proc() {
t := testing.T{}
test_libc_complex(&t)
fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
if TEST_fail > 0 {
os.exit(1)
}
}
@@ -0,0 +1,91 @@
package test_core_libc
import "core:testing"
import "core:fmt"
import "core:c/libc"
reldiff :: proc(lhs, rhs: $T) -> f64 {
if lhs == rhs {
return 0.
}
amean := f64((abs(lhs)+abs(rhs)) / 2.)
adiff := f64(abs(lhs - rhs))
out := adiff / amean
return out
}
isclose :: proc(lhs, rhs: $T, rtol:f64 = 1e-12, atol:f64 = 1e-12) -> bool {
adiff := f64(abs(lhs - rhs))
if adiff < atol {
return true
}
rdiff := reldiff(lhs, rhs)
if rdiff < rtol {
return true
}
fmt.printf("not close -- lhs:%v rhs:%v -- adiff:%e rdiff:%e\n",lhs, rhs, adiff, rdiff)
return false
}
// declaring here so they can be used as function pointers
libc_pow :: proc(x, y: libc.complex_double) -> libc.complex_double {
return libc.pow(x,y)
}
libc_powf :: proc(x, y: libc.complex_float) -> libc.complex_float {
return libc.pow(x,y)
}
@test
test_libc_complex :: proc(t: ^testing.T) {
test_libc_pow_binding(t, libc.complex_double, f64, libc_pow, 1e-12, 1e-12)
// f32 needs more atol for comparing values close to zero
test_libc_pow_binding(t, libc.complex_float, f32, libc_powf, 1e-12, 1e-5)
}
@test
test_libc_pow_binding :: proc(t: ^testing.T, $LIBC_COMPLEX:typeid, $F:typeid, pow: proc(LIBC_COMPLEX, LIBC_COMPLEX) -> LIBC_COMPLEX,
rtol: f64, atol: f64) {
// Tests that c/libc/pow(f) functions have two arguments and that the function works as expected for simple inputs
{
// tests 2^n
expected_real : F = 1./16.
expected_imag : F = 0.
complex_base := LIBC_COMPLEX(complex(F(2.), F(0.)))
for n in -4..=4 {
complex_power := LIBC_COMPLEX(complex(F(n), F(0.)))
result := pow(complex_base, complex_power)
expect(t, isclose(expected_real, F(real(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol))
expect(t, isclose(expected_imag, F(imag(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol))
expected_real *= 2
}
}
{
// tests (2i)^n
value : F = 1/16.
expected_real, expected_imag : F
complex_base := LIBC_COMPLEX(complex(F(0.), F(2.)))
for n in -4..=4 {
complex_power := LIBC_COMPLEX(complex(F(n), F(0.)))
result := pow(complex_base, complex_power)
switch n%%4 {
case 0:
expected_real = value
expected_imag = 0.
case 1:
expected_real = 0.
expected_imag = value
case 2:
expected_real = -value
expected_imag = 0.
case 3:
expected_real = 0.
expected_imag = -value
}
expect(t, isclose(expected_real, F(real(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, re(%v)) is greater than specified rtol:%e", F{}, n, expected_real, result, rtol))
expect(t, isclose(expected_imag, F(imag(result)), rtol, atol), fmt.tprintf("ftype:%T, n:%v reldiff(%v, im(%v)) is greater than specified rtol:%e", F{}, n, expected_imag, result, rtol))
value *= 2
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
package odin_gl package vendor_gl
GL_DEBUG :: #config(GL_DEBUG, ODIN_DEBUG) GL_DEBUG :: #config(GL_DEBUG, ODIN_DEBUG)
+1 -1
View File
@@ -1,4 +1,4 @@
package odin_gl package vendor_gl
GL_Enum :: enum u64 { GL_Enum :: enum u64 {
FALSE = 0, FALSE = 0,
+1 -1
View File
@@ -1,4 +1,4 @@
package odin_gl package vendor_gl
// Helper for loading shaders into a program // Helper for loading shaders into a program
+1 -1
View File
@@ -1,4 +1,4 @@
package odin_gl package vendor_gl
loaded_up_to: [2]int loaded_up_to: [2]int
loaded_up_to_major := 0 loaded_up_to_major := 0
+1 -1
View File
@@ -1,4 +1,4 @@
package odin_gl package vendor_gl
#assert(size_of(bool) == size_of(u8)) #assert(size_of(bool) == size_of(u8))
+1 -1
View File
@@ -1,4 +1,4 @@
package botan_bindings package vendor_botan
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package botan_blake2b package vendor_botan_blake2b
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package gost package vendor_gost
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package keccak package vendor_keccak
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package md4 package vendor_md4
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package md5 package vendor_md5
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package ripemd package vendor_ripemd
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package sha1 package vendor_sha1
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package sha2 package vendor_sha2
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package sha3 package vendor_sha3
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package shake package vendor_shake
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package siphash package vendor_siphash
/* /*
Copyright 2022 zhibog Copyright 2022 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package skein512 package vendor_skein512
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package sm3 package vendor_sm3
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package streebog package vendor_streebog
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package tiger package vendor_tiger
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -1,4 +1,4 @@
package whirlpool package vendor_whirlpool
/* /*
Copyright 2021 zhibog Copyright 2021 zhibog
+1 -1
View File
@@ -4,7 +4,7 @@
Original authors: John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. Original authors: John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
See LICENSE for license details. See LICENSE for license details.
*/ */
package commonmark package vendor_commonmark
import "core:c" import "core:c"
import "core:c/libc" import "core:c/libc"
+1 -1
View File
@@ -5,7 +5,7 @@
Original authors: John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer. Original authors: John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
See LICENSE for license details. See LICENSE for license details.
*/ */
package commonmark package vendor_commonmark
/* /*
Parsing - Simple interface: Parsing - Simple interface:
+1 -1
View File
@@ -1,4 +1,4 @@
package ggpo package vendor_ggpo
foreign import lib "GGPO.lib" foreign import lib "GGPO.lib"
+4 -4
View File
@@ -1,9 +1,9 @@
package zlib package vendor_zlib
import "core:c" import "core:c"
when ODIN_OS == .Windows do foreign import zlib "libz.lib" when ODIN_OS == .Windows { foreign import zlib "libz.lib" }
when ODIN_OS == .Linux do foreign import zlib "system:z" when ODIN_OS == .Linux { foreign import zlib "system:z" }
VERSION :: "1.2.12" VERSION :: "1.2.12"
VERNUM :: 0x12c0 VERNUM :: 0x12c0
@@ -259,4 +259,4 @@ gzgetc :: #force_inline proc(file: gzFile) -> c.int {
return ch return ch
} }
return gzgetc_unique(file) return gzgetc_unique(file)
} }