mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-04-17 17:29:02 +02:00
[svn r96] Updated to DMD 1.023.
Regular bugfixes.
This commit is contained in:
29
test/bug51.d
29
test/bug51.d
@@ -1,26 +1,5 @@
|
||||
module bug51;
|
||||
|
||||
import std.stdint;
|
||||
|
||||
union in6_addr
|
||||
{
|
||||
private union _in6_u_t
|
||||
{
|
||||
uint8_t[16] u6_addr8;
|
||||
uint16_t[8] u6_addr16;
|
||||
uint32_t[4] u6_addr32;
|
||||
}
|
||||
_in6_u_t in6_u;
|
||||
|
||||
uint8_t[16] s6_addr8;
|
||||
uint16_t[8] s6_addr16;
|
||||
uint32_t[4] s6_addr32;
|
||||
}
|
||||
|
||||
|
||||
const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
|
||||
const in6_addr IN6ADDR_LOOPBACK = { s6_addr8: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] };
|
||||
|
||||
void main()
|
||||
{
|
||||
}
|
||||
const ubyte[3] arr1 = 0;
|
||||
const ubyte[3] arr2 = [0];
|
||||
const ubyte[3] arr3 = [0:1];
|
||||
void main() {}
|
||||
|
||||
20
test/bug55.d
Normal file
20
test/bug55.d
Normal file
@@ -0,0 +1,20 @@
|
||||
module bug55;
|
||||
|
||||
int atoi(char[] s) {
|
||||
int i, fac=1;
|
||||
bool neg = (s.length) && (s[0] == '-');
|
||||
char[] a = neg ? s[1..$] : s;
|
||||
foreach_reverse(c; a) {
|
||||
i += (c-'0') * fac;
|
||||
fac *= 10;
|
||||
}
|
||||
return !neg ? i : -i;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
printf("64213 = %d\n", atoi("64213"));
|
||||
printf("-64213 = %d\n", atoi("-64213"));
|
||||
assert(atoi("64213") == 64213);
|
||||
assert(atoi("-64213") == -64213);
|
||||
}
|
||||
8
test/bug56.d
Normal file
8
test/bug56.d
Normal file
@@ -0,0 +1,8 @@
|
||||
module bug56;
|
||||
|
||||
void main()
|
||||
{
|
||||
int[] a;
|
||||
a = [1,2,3];
|
||||
{int[] b = [4,5,6];}
|
||||
}
|
||||
117
test/ray.d
Normal file
117
test/ray.d
Normal file
@@ -0,0 +1,117 @@
|
||||
//import std.stdio, std.math, std.string;
|
||||
//import tools.base;
|
||||
|
||||
int atoi(char[] s) {
|
||||
int i, fac=1;
|
||||
bool neg = (s.length) && (s[0] == '-');
|
||||
char[] a = neg ? s[1..$] : s;
|
||||
foreach_reverse(c; a) {
|
||||
i += (c-'0') * fac;
|
||||
fac *= 10;
|
||||
}
|
||||
return !neg ? i : -i;
|
||||
}
|
||||
|
||||
pragma(LLVM_internal, "intrinsic", "llvm.sqrt.f64")
|
||||
double sqrt(double val);
|
||||
|
||||
double delta;
|
||||
static this() { delta=sqrt(real.epsilon); }
|
||||
|
||||
struct Vec {
|
||||
double x, y, z;
|
||||
Vec opAdd(ref Vec other) { return Vec(x+other.x, y+other.y, z+other.z); }
|
||||
Vec opSub(ref Vec other) { return Vec(x-other.x, y-other.y, z-other.z); }
|
||||
Vec opMul(double a) { return Vec(x*a, y*a, z*a); }
|
||||
double dot(ref Vec other) { return x*other.x+y*other.y+z*other.z; }
|
||||
Vec unitise() { return opMul(1.0/sqrt(dot(*this))); }
|
||||
}
|
||||
|
||||
struct Pair(T, U) { T first; U second; }
|
||||
typedef Pair!(double, Vec) Hit;
|
||||
|
||||
struct Ray { Vec orig, dir; }
|
||||
|
||||
class Scene {
|
||||
//abstract void intersect(ref Hit, ref Ray);
|
||||
void intersect(ref Hit, ref Ray) {}
|
||||
}
|
||||
|
||||
class Sphere : Scene {
|
||||
Vec center;
|
||||
double radius;
|
||||
//mixin This!("center, radius");
|
||||
this(ref Vec c, double r)
|
||||
{
|
||||
center = c;
|
||||
radius = r;
|
||||
}
|
||||
double ray_sphere(ref Ray ray) {
|
||||
auto v = center - ray.orig, b = v.dot(ray.dir), disc=b*b - v.dot(v) + radius*radius;
|
||||
if (disc < 0) return double.infinity;
|
||||
auto d = sqrt(disc), t2 = b + d;
|
||||
if (t2 < 0) return double.infinity;
|
||||
auto t1 = b - d;
|
||||
return (t1 > 0 ? t1 : t2);
|
||||
}
|
||||
void intersect(ref Hit hit, ref Ray ray) {
|
||||
auto lambda = ray_sphere(ray);
|
||||
if (lambda < hit.first)
|
||||
hit = Hit(lambda, (ray.orig + lambda*ray.dir - center).unitise);
|
||||
}
|
||||
}
|
||||
|
||||
class Group : Scene {
|
||||
Sphere bound;
|
||||
Scene[] children;
|
||||
//mixin This!("bound, children");
|
||||
this (Sphere s, Scene[] c)
|
||||
{
|
||||
bound = s;
|
||||
children = c;
|
||||
}
|
||||
void intersect(ref Hit hit, ref Ray ray) {
|
||||
auto l = bound.ray_sphere(ray);
|
||||
if (l < hit.first) foreach (child; children) child.intersect(hit, ray);
|
||||
}
|
||||
}
|
||||
|
||||
double ray_trace(ref Vec light, ref Ray ray, Scene s) {
|
||||
auto hit=Hit(double.infinity, Vec(0, 0, 0));
|
||||
s.intersect(hit, ray);
|
||||
if (hit.first == double.infinity) return 0.0;
|
||||
auto g = hit.second.dot(light);
|
||||
if (g >= 0) return 0.0;
|
||||
auto p = ray.orig + ray.dir*hit.first + hit.second*delta;
|
||||
auto hit2=Hit(double.infinity, Vec(0, 0, 0));
|
||||
s.intersect(hit2, Ray(p, light*-1.0));
|
||||
return (hit2.first < double.infinity ? 0 : -g);
|
||||
}
|
||||
|
||||
Scene create(int level, ref Vec c, double r) {
|
||||
auto s = new Sphere(c, r);
|
||||
if (level == 1) return s;
|
||||
Scene[] children=[s];
|
||||
double rn = 3*r/sqrt(12.0);
|
||||
for (int dz=-1; dz<=1; dz+=2)
|
||||
for (int dx=-1; dx<=1; dx+=2)
|
||||
children~=create(level-1, c + Vec(dx, 1, dz)*rn, r/2);
|
||||
return new Group(new Sphere(c, 3*r), children);
|
||||
}
|
||||
|
||||
void main(string[] args) {
|
||||
int level = (args.length==3 ? args[1].atoi() : 9),
|
||||
n = (args.length==3 ? args[2].atoi() : 512), ss = 4;
|
||||
auto light = Vec(-1, -3, 2).unitise();
|
||||
auto s=create(level, Vec(0, -1, 0), 1);
|
||||
printf("P5\n%d %d\n255", n, n);
|
||||
for (int y=n-1; y>=0; --y)
|
||||
for (int x=0; x<n; ++x) {
|
||||
double g=0;
|
||||
for (int d=0; d<ss*ss; ++d) {
|
||||
auto dir=Vec(x+(d%ss)*1.0/ss-n/2.0, y+(d/ss)*1.0/ss-n/2.0, n).unitise();
|
||||
g += ray_trace(light, Ray(Vec(0, 0, -4), dir), s);
|
||||
}
|
||||
printf("%c", cast(ubyte)(0.5 + 255.0 * g / (ss*ss)));
|
||||
}
|
||||
}
|
||||
12
test/sqrts.d
Normal file
12
test/sqrts.d
Normal file
@@ -0,0 +1,12 @@
|
||||
module sqrts;
|
||||
|
||||
import std.c.math;
|
||||
|
||||
double sqrt(double d)
|
||||
{
|
||||
return std.c.math.sqrt(d);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user