diff --git a/Yolol.Analysis/ControlFlowGraph/Builder.cs b/Yolol.Analysis/ControlFlowGraph/Builder.cs index 7e43f9c..b8b42f2 100644 --- a/Yolol.Analysis/ControlFlowGraph/Builder.cs +++ b/Yolol.Analysis/ControlFlowGraph/Builder.cs @@ -143,7 +143,7 @@ private void HandleGoto(IMutableControlFlowGraph cfg, Goto @goto, IMutableBasicB if (dest.Type == Execution.Type.Number) { // We know exactly where this is going, jump to that line - var line = Math.Clamp((int)dest.Number.Value, 1, _maxLines); + var line = Math.Clamp((int)dest.Number, 1, _maxLines); var destBlock = GetLineEntryBlock(cfg, line); cfg.CreateEdge(block, destBlock, EdgeType.GotoConstNum); } diff --git a/Yolol.Analysis/DataFlowGraph/DataFlowGraph.cs b/Yolol.Analysis/DataFlowGraph/DataFlowGraph.cs index 70622d5..4de50e4 100644 --- a/Yolol.Analysis/DataFlowGraph/DataFlowGraph.cs +++ b/Yolol.Analysis/DataFlowGraph/DataFlowGraph.cs @@ -507,7 +507,7 @@ protected override IDataFlowGraphExpressionNode Visit(Negate neg) protected override IDataFlowGraphExpressionNode Visit(ConstantNumber con) { - var op = new InputConst(Guid.NewGuid(), con.Value.Value); + var op = new InputConst(Guid.NewGuid(), new Value(con.Value)); _dataFlowGraph._inputs.Add(op); return op; } diff --git a/Yolol.Analysis/SAT/IModelVariable.cs b/Yolol.Analysis/SAT/IModelVariable.cs index 7aa206c..543a945 100644 --- a/Yolol.Analysis/SAT/IModelVariable.cs +++ b/Yolol.Analysis/SAT/IModelVariable.cs @@ -45,7 +45,7 @@ internal void AssertEq(Value value) switch (value.Type) { case Type.Number: - _model.Solver.Assert(ctx.MkEq(_numValue, _model.Context.MkInt((value.Number.Value * Number.Scale).ToString(CultureInfo.InvariantCulture)))); + _model.Solver.Assert(ctx.MkEq(_numValue, _model.Context.MkInt(((long)value.Number * Number.Scale).ToString(CultureInfo.InvariantCulture)))); return; case Type.String: @@ -493,7 +493,7 @@ ModelVariable GetOrCreateVar(BaseExpression sub) if (sub is ConstantNumber num) { var n = _model.GetOrCreateVariable(new VariableName(Guid.NewGuid().ToString())); - n.AssertEq(num.Value.Value); + n.AssertEq(num.Value); return n; } @@ -536,7 +536,7 @@ public bool CanBeValue(Value v) return _model.Solver.IsSatisfiable( ctx.MkAnd( ctx.MkEq(_type, _model.NumType), - ctx.MkEq(_numValue, _model.Context.MkInt((v.Number.Value * Number.Scale).ToString())) + ctx.MkEq(_numValue, _model.Context.MkInt(((long)v.Number * Number.Scale).ToString())) ) ); } @@ -554,7 +554,7 @@ public bool CannotBeOtherValue(Value v) return !_model.Solver.IsSatisfiable(ctx.MkNot(ctx.MkEq(_strValue, _model.Context.MkString(v.String)))); if (v.Type == Type.Number) - return !_model.Solver.IsSatisfiable(ctx.MkNot(ctx.MkEq(_numValue, _model.Context.MkInt((v.Number.Value * Number.Scale).ToString())))); + return !_model.Solver.IsSatisfiable(ctx.MkNot(ctx.MkEq(_numValue, _model.Context.MkInt(((long)v.Number * Number.Scale).ToString())))); throw new NotSupportedException($"unknown value type {v.Type}"); } diff --git a/Yolol.Analysis/TreeVisitor/Reduction/ConstantCompressor.cs b/Yolol.Analysis/TreeVisitor/Reduction/ConstantCompressor.cs index b762c3a..f534732 100644 --- a/Yolol.Analysis/TreeVisitor/Reduction/ConstantCompressor.cs +++ b/Yolol.Analysis/TreeVisitor/Reduction/ConstantCompressor.cs @@ -65,7 +65,7 @@ void Submit(BaseExpression exp) var b = idx / 10m; try { - var log = Math.Log((double)value.Value, (double)b); + var log = Math.Log((double)(decimal)value, (double)b); if (double.IsNaN(log)) continue; @@ -146,10 +146,10 @@ private static BaseExpression BestFraction(Number number) } } - if (number.Value >= 1) + if (number >= 1) return new ConstantNumber(number); - var (fn, fd) = RealToFraction((double)number.Value, 0.001f); + var (fn, fd) = RealToFraction((double)number, 0.001f); var replacement = new Divide(new ConstantNumber((decimal)fn), new ConstantNumber((decimal)fd)); @@ -164,7 +164,7 @@ private static BaseExpression BestFraction(Number number) var atan = new ArcTan(new ConstantNumber(number)).TryStaticEvaluate(); if (!atan.HasValue) return null; - var atanFloor = (long)atan.Value.Number.Value; + var atanFloor = (long)(decimal)atan.Value.Number; var offset = number - atan.Value; diff --git a/Yolol.Analysis/TreeVisitor/Reduction/OpNumByConstNumCompressor.cs b/Yolol.Analysis/TreeVisitor/Reduction/OpNumByConstNumCompressor.cs index bd056fc..89dc9f0 100644 --- a/Yolol.Analysis/TreeVisitor/Reduction/OpNumByConstNumCompressor.cs +++ b/Yolol.Analysis/TreeVisitor/Reduction/OpNumByConstNumCompressor.cs @@ -27,7 +27,7 @@ protected override BaseExpression Visit(Multiply mul) { BaseExpression? HandleSingleSideNumber(Number number, BaseExpression other) { - return number.Value switch { + return (long)number switch { -1 => base.Visit(new Negate(new Bracketed(other))), 0 => new ConstantNumber(0), 1 => base.Visit(other), @@ -86,7 +86,7 @@ protected override BaseExpression Visit(Divide div) if (!rv.HasValue) return base.Visit(div); - return rv.Value.Value switch { + return (long)rv.Value switch { -1 => base.Visit(new Negate(new Bracketed(base.Visit(div.Left)))), 0 => new ErrorExpression(), 1 => base.Visit(new Bracketed(base.Visit(div.Left))), @@ -98,7 +98,7 @@ protected override BaseExpression Visit(Add add) { BaseExpression? HandleSingleSideNumber(Number number, BaseExpression other) { - return number.Value switch + return (long)number switch { 0 => base.Visit(new Bracketed(other)), _ => null, @@ -149,7 +149,7 @@ protected override BaseExpression Visit(Exponent exp) if (!rv.HasValue) return base.Visit(exp); - return rv.Value.Value switch { + return (long)rv.Value switch { 0 => base.Visit(new ConstantNumber(1)), 1 => base.Visit(new Bracketed(base.Visit(exp.Left))), -1 => base.Visit(new Divide(new ConstantNumber(1), new Bracketed(exp.Left))), diff --git a/Yolol.Cylon/JSON/YololValueConverter.cs b/Yolol.Cylon/JSON/YololValueConverter.cs index 5e95201..b0c6335 100644 --- a/Yolol.Cylon/JSON/YololValueConverter.cs +++ b/Yolol.Cylon/JSON/YololValueConverter.cs @@ -13,7 +13,7 @@ public override void WriteJson(JsonWriter writer, Value value, JsonSerializer se if (value.Type == Execution.Type.String) writer.WriteValue(value.String); else - writer.WriteValue(value.Number.Value); + writer.WriteValue((decimal)value.Number); } public override Value ReadJson(JsonReader reader, Type objectType, Value existingValue, bool hasExistingValue, JsonSerializer serializer) diff --git a/Yolol/Execution/Number.cs b/Yolol/Execution/Number.cs index 1966ab6..6457b82 100644 --- a/Yolol/Execution/Number.cs +++ b/Yolol/Execution/Number.cs @@ -3,60 +3,27 @@ namespace Yolol.Execution { - public struct Number + public readonly struct Number : IEquatable { public const int Scale = 1000; public const int Decimals = 3; - public static readonly Number MinValue = new Number(-9223372036854775.808m); - public static readonly Number MaxValue = new Number(9223372036854775.807m); - public static readonly Number One = new Number(1); + public static readonly Number MinValue = new Number(long.MinValue); + public static readonly Number MaxValue = new Number(long.MaxValue); + public static readonly Number One = new Number(1000); public static readonly Number Zero = new Number(0); - public decimal Value { get; } + private long Value { get; } - private Number(decimal num) + private Number(long num) { Value = num; } - private Number Truncate() - { - var d = Value; - - // https://stackoverflow.com/a/43639947/108234 - var r = Math.Round(d, Decimals); - if (d > 0 && r > d) - return new Number(r - new decimal(1, 0, 0, false, Decimals)); - else if (d < 0 && r < d) - return new Number(r + new decimal(1, 0, 0, false, Decimals)); - - return new Number(r); - - // Naieve approach - //return new Number(Math.Truncate(Value * Scale) / Scale); - } - - private Number RangeCheck() - { - if (Value > MaxValue.Value) - return MaxValue; - - if (Value < MinValue.Value) - return MinValue; - - return this; - } - - private static Number SafeNew(decimal num) - { - return new Number(num).Truncate().RangeCheck(); - } - public string ToString(CultureInfo culture) { - return Value.ToString("0.###", culture); + return ((decimal)Value / Scale).ToString(culture); } public override string ToString() @@ -66,7 +33,7 @@ public override string ToString() public bool Equals(Number other) { - return this == other; + return Value == other.Value; } public override bool Equals(object obj) @@ -81,41 +48,66 @@ public override int GetHashCode() public static Number Parse(string s) { - // First check if the number is so colossal that a decimal can't hold it + // First check if the number is out of the valid range var d = double.Parse(s); - if (d >= (double)MaxValue.Value) + if (d >= MaxValue.Value) return MaxValue; - else if (d <= (double)MinValue.Value) + else if (d <= MinValue.Value) return MinValue; - // It's within the safe range, parse as decimal - return SafeNew(decimal.Parse(s)); + return decimal.Parse(s); } public static implicit operator Number(int i) { - return new Number(i); + return new Number(i * (long)Scale); } public static explicit operator Number(double i) { - return SafeNew((decimal)i); + var n = i * Scale; + if (n > MaxValue.Value) + return MaxValue; + if (n < MinValue.Value) + return MinValue; + + return new Number((long)n); } public static implicit operator Number(decimal d) { - return SafeNew(d); + var n = d * Scale; + if (n > MaxValue.Value) + return MaxValue; + if (n < MinValue.Value) + return MinValue; + + return new Number((long)(d * Scale)); + } + + public static explicit operator decimal(Number n) + { + return ((decimal)n.Value) / Scale; + } + + public static explicit operator int(Number n) + { + return (int)(n.Value / Scale); + } + + public static explicit operator float(Number n) + { + return ((float)n.Value) / Scale; } public static Number operator %(Number l, Number r) { - var v = new Number(l.Value % r.Value); - return v.Truncate(); + return new Number(l.Value % r.Value); } public static Number operator *(Number l, Number r) { - return SafeNew(l.Value * r.Value); + return new Number((l.Value * r.Value) / Scale); } public static Number operator /(Number l, Number r) @@ -123,22 +115,22 @@ public static implicit operator Number(decimal d) if (r == Zero) throw new ExecutionException("Divide by zero"); - return SafeNew(l.Value / r.Value); + return new Number((l.Value * Scale) / r.Value); } public static Number operator +(Number l, Number r) { - return SafeNew(l.Value + r.Value); + return new Number(l.Value + r.Value); } public static Number operator -(Number l, Number r) { - return SafeNew(l.Value - r.Value); + return new Number(l.Value - r.Value); } public static Number operator -(Number n) { - return new Number(-n.Value).RangeCheck(); + return new Number(-n.Value); } public static bool operator >(Number l, Number r) diff --git a/Yolol/Execution/Value.cs b/Yolol/Execution/Value.cs index f2066bd..e9404fa 100644 --- a/Yolol/Execution/Value.cs +++ b/Yolol/Execution/Value.cs @@ -99,7 +99,7 @@ public bool ToBool() public object ToObject() { if (Type == Type.Number) - return Number.Value; + return (decimal)Number; else return String; } @@ -291,7 +291,7 @@ public static Value Exponent(Value left, Value right) switch (left.Type, right.Type) { case (Type.Number, Type.Number): - var v = Math.Pow((double)left.Number.Value, (double)right.Number.Value); + var v = Math.Pow((float)left.Number, (float)right.Number); if (double.IsPositiveInfinity(v)) return new Value(Number.MaxValue); @@ -341,17 +341,19 @@ public static Value Sqrt(Value value) if (value.Number < 0) throw new ExecutionException("Attempted to Sqrt a negative value"); - return (Number)(decimal)Math.Sqrt((double)value.Number.Value); + return (Number)(decimal)Math.Sqrt((float)value.Number); } - private static decimal ToDegrees(double radians) + private static float ToDegrees(float radians) { - return (decimal)(radians * (180.0 / Math.PI)); + const float rad2Deg = 360f / ((float)Math.PI * 2); + return radians * rad2Deg; } - private static double ToRadians(decimal degrees) + private static float ToRadians(float degrees) { - return Math.PI * (double)degrees / 180.0; + const float deg2Rad = (float)Math.PI * 2 / 360f; + return degrees * deg2Rad; } public static Value Sin(Value value) @@ -359,7 +361,10 @@ public static Value Sin(Value value) if (value.Type == Type.String) throw new ExecutionException($"Attempted to `Sin` a string value"); - return new Value((decimal)Math.Sin(ToRadians(value.Number.Value))); + var r = ToRadians((float)value.Number); + var s = Math.Round(Math.Sin(r), 3); + + return new Value((Number)s); } public static Value Cos(Value value) @@ -367,15 +372,23 @@ public static Value Cos(Value value) if (value.Type == Type.String) throw new ExecutionException($"Attempted to `Cos` a string value"); - return new Value((decimal)Math.Cos(ToRadians(value.Number.Value))); + var r = ToRadians((float)value.Number); + var s = Math.Round(Math.Cos(r), 3); + + return new Value((Number)s); } public static Value Tan(Value value) { if (value.Type == Type.String) throw new ExecutionException($"Attempted to `Tan` a string value"); + if (value.Number == 90) + return Number.MaxValue; + + var r = ToRadians((float)value.Number); + var s = Math.Round(Math.Tan(r), 3); - return new Value((decimal)Math.Tan(ToRadians(value.Number.Value))); + return new Value((Number)s); } public static Value ArcTan(Value value) @@ -383,7 +396,7 @@ public static Value ArcTan(Value value) if (value.Type == Type.String) throw new ExecutionException($"Attempted to `ATan` a string value"); - return new Value(ToDegrees(Math.Atan((double)value.Number.Value))); + return new Value((Number)ToDegrees((float)Math.Atan((float)value.Number))); } public static Value ArcSin(Value value) @@ -391,7 +404,7 @@ public static Value ArcSin(Value value) if (value.Type == Type.String) throw new ExecutionException($"Attempted to `ASin` a string value"); - return new Value(ToDegrees(Math.Asin((double)value.Number.Value))); + return new Value((Number)ToDegrees((float)Math.Asin((float)value.Number))); } public static Value ArcCos(Value value) @@ -399,7 +412,7 @@ public static Value ArcCos(Value value) if (value.Type == Type.String) throw new ExecutionException($"Attempted to `ACos` a string value"); - return new Value(ToDegrees(Math.Acos((double)value.Number.Value))); + return new Value((Number)ToDegrees((float)Math.Acos((float)value.Number))); } public BaseExpression ToConstant() diff --git a/Yolol/Grammar/AST/Statements/Goto.cs b/Yolol/Grammar/AST/Statements/Goto.cs index 3571c24..03850aa 100644 --- a/Yolol/Grammar/AST/Statements/Goto.cs +++ b/Yolol/Grammar/AST/Statements/Goto.cs @@ -25,7 +25,7 @@ public override ExecutionResult Evaluate(MachineState state) if (dest.Type != Type.Number) throw new ExecutionException($"Attempted to goto to a value of type `{dest.Type}`"); - var line = Math.Min(state.MaxLineNumber, Math.Max(1, (int)dest.Number.Value)); + var line = Math.Min(state.MaxLineNumber, Math.Max(1, (int)dest.Number)); return new ExecutionResult(line); } diff --git a/YololEmulator.Tests/Expressions/Num/Cosine.cs b/YololEmulator.Tests/Expressions/Num/Cosine.cs index d06b413..b2d8722 100644 --- a/YololEmulator.Tests/Expressions/Num/Cosine.cs +++ b/YololEmulator.Tests/Expressions/Num/Cosine.cs @@ -18,7 +18,7 @@ public void Cos45() { var result = TestExecutor.Execute("a = cos(45)"); var a = result.GetVariable("a"); - Assert.AreEqual(0.707m, a.Value.Number.Value); + Assert.AreEqual(0.707m, a.Value.Number); } [TestMethod] diff --git a/YololEmulator.Tests/Expressions/Num/Sine.cs b/YololEmulator.Tests/Expressions/Num/Sine.cs index 2d48160..7c58b2b 100644 --- a/YololEmulator.Tests/Expressions/Num/Sine.cs +++ b/YololEmulator.Tests/Expressions/Num/Sine.cs @@ -18,7 +18,7 @@ public void Sin45() { var result = TestExecutor.Execute("a = sin(45)"); var a = result.GetVariable("a"); - Assert.AreEqual(0.707m, a.Value.Number.Value); + Assert.AreEqual(0.707m, a.Value.Number); } [TestMethod] diff --git a/YololEmulator.Tests/NumberTests.cs b/YololEmulator.Tests/NumberTests.cs index 364ddb5..391d0ca 100644 --- a/YololEmulator.Tests/NumberTests.cs +++ b/YololEmulator.Tests/NumberTests.cs @@ -4,17 +4,61 @@ namespace YololEmulator.Tests { [TestClass] - public class NumberTests + public class Number6464Tests { + [TestMethod] + public void IntToNumber() + { + var n = (Number)1000; + Assert.AreEqual(1000, n); + } + + [TestMethod] + public void DoubleToNumber() + { + var n = (Number)(double)1000; + Assert.AreEqual(1000, n); + } + + [TestMethod] + public void DecimalToNumber() + { + var n = (Number)1000m; + Assert.AreEqual(1000, n); + } + [TestMethod] public void TruncateOnConstruction() { var n = (Number)1.234567m; - Assert.AreEqual(1.234m, n.Value); + Assert.AreEqual(1.234m, n); Assert.AreEqual("1.234", n.ToString()); } + [TestMethod] + public void ToStringRemovesDecimalZeros() + { + var n = (Number)0.000m; + Assert.AreEqual("0", n.ToString()); + } + + [TestMethod] + public void ToStringRemovesDecimalZerosAfterLastDecimal() + { + var n = (Number)0.010m; + + Assert.AreEqual(0.010m, n); + Assert.AreEqual("0.01", n.ToString()); + } + + [TestMethod] + public void ToStringNegative() + { + var n = (Number)(-1.020m); + Assert.AreEqual("-1.02", n.ToString()); + } + [TestMethod] public void Equal() { @@ -53,10 +97,80 @@ public void NotEqual() } [TestMethod] - public void BigNegativeParsing() + public void Subtract() + { + var a = (Number)1.010m; + var b = (Number)19.077m; + + var c = b - a; + + Assert.AreEqual((Number)18.067, c); + } + + [TestMethod] + public void Add() { - var r = TestExecutor.Execute("a = -9223372036854775.808"); - Assert.AreEqual(-9223372036854775.808m, r.GetVariable("a").Value.Number); + var a = (Number)1083m; + var b = (Number)12.77m; + + var c = b + a; + + Assert.AreEqual((Number)1095.77, c); + } + + [TestMethod] + public void Multiply() + { + var a = (Number)17; + var b = (Number)9; + + var c = a * b; + + Assert.AreEqual((Number)153, c); + } + + [TestMethod] + public void Divide() + { + var a = (Number)153; + var b = (Number)9; + + var c = a / b; + + Assert.AreEqual((Number)17, c); + } + + [TestMethod] + public void ModBasic() + { + var a = (Number)7; + var b = (Number)3; + + var c = a % b; + + Assert.AreEqual((Number)1, c); + } + + [TestMethod] + public void ModDecimal() + { + var a = (Number)7; + var b = (Number)3.2; + + var c = a % b; + + Assert.AreEqual((Number)0.6, c); + } + + [TestMethod] + public void ModNegative() + { + var a = (Number)(-7); + var b = (Number)3; + + var c = a % b; + + Assert.AreEqual((Number)(-1), c); } } } diff --git a/YololEmulator.Tests/Playground.cs b/YololEmulator.Tests/Playground.cs index c26bf55..bae6c94 100644 --- a/YololEmulator.Tests/Playground.cs +++ b/YololEmulator.Tests/Playground.cs @@ -4,9 +4,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Yolol.Analysis; using Yolol.Analysis.TreeVisitor; -using Yolol.Analysis.TreeVisitor.Reduction; +using Yolol.Execution; using Yolol.Grammar; -using Yolol.Grammar.AST.Expressions; using Yolol.Grammar.AST.Statements; namespace YololEmulator.Tests diff --git a/YololEmulator.Tests/YololEmulator.Tests.csproj b/YololEmulator.Tests/YololEmulator.Tests.csproj index 61250ba..6d81971 100644 --- a/YololEmulator.Tests/YololEmulator.Tests.csproj +++ b/YololEmulator.Tests/YololEmulator.Tests.csproj @@ -8,6 +8,8 @@ 8.0 AnyCPU;x64 + + @@ -29,8 +31,8 @@ - - + + diff --git a/YololEmulator/Network/ConsoleInputDeviceNetwork.cs b/YololEmulator/Network/ConsoleInputDeviceNetwork.cs index ec4a035..e2a000c 100644 --- a/YololEmulator/Network/ConsoleInputDeviceNetwork.cs +++ b/YololEmulator/Network/ConsoleInputDeviceNetwork.cs @@ -57,10 +57,16 @@ public Value Value continue; if (value.StartsWith('"') && value.EndsWith('"')) - return new Value(value[1..^1]); + { + _savedValue = new Value(value[1..^1]); + return _savedValue.Value; + } if (decimal.TryParse(value, out var result)) - return new Value(result); + { + _savedValue = new Value(result); + return _savedValue.Value; + } Console.WriteLine(" -> Could not parse as a string or a number!"); } diff --git a/YololEmulator/XOR16.lol b/YololEmulator/XOR16.lol new file mode 100644 index 0000000..41d54a6 --- /dev/null +++ b/YololEmulator/XOR16.lol @@ -0,0 +1,87 @@ +:o+=(a+b)%d*2^n+++(a/2+b/2)%d*2^n+++(a/4+b/4)%d*2^n++a/=8b/=8goto1/m-- // Loop body +x/=n>0:o+=(a+b)%d*2^n+++(a/2+b/2)%d*2^n++:done=1:o*=c // Submit +c=1000a=:a/c b=:b/c d=2/c:o=0n=0m=4:o+=(a+b)%d*2^n++a/=2b/=2goto1 // Setup + +// Current best: ^ + +:o+=(a+b)%d*x+(a/2+b/2)%d*x+(a/4+b/4)*x+(a/4+b/4)*x a/=8b/=8 + +/--------//--------//--------//--------//--------//--------//--------/ + + +c=1000 a=:a/c b=:b/c d=2/c :o=0 n=0 +:o+=(a+b)%d*2^n+++(a/2+b/2)%d*2^n++ a/=4b/=4goto3-(a+b>0) +:done=1 :o*=c goto1 + + +:o+=(a+b)%d*n n*=2a/=2b/=2 +:o+=(a+b)%d*2^n++ a/=2b/=2 +o+=(:a/n+:b/n)%d*n n/=2 + +/--------//--------//--------//--------//--------//--------//--------/ + +c=1000d=2/c n=(2^15)*c o=(:a/n+:b/n)%d*n n/=2 +o+=(:a/n+:b/n)%d*n n/=2o+=(:a/n+:b/n)%d*n n/=2o+=(:a/n+:b/n)%d*n n/=2 +o+=(:a/n+:b/n)%d*n n/=2o+=(:a/n+:b/n)%d*n n/=2 goto2/(n>=c) +:o=o goto:done++ + +/--------//--------//--------//--------//--------//--------//--------/ + +// Second best: v + +c=1000d=2/c:o=0n=(2^15)*c +:o+=(:a/n+:b/n)%d*n n/=2:o+=(:a/n+:b/n)%d*n n/=2f=n8.0 enable AnyCPU;x64 + 5.0.0 @@ -61,6 +62,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/YololEmulator/test.lol b/YololEmulator/test.lol index 91f3696..53c7d83 100644 --- a/YololEmulator/test.lol +++ b/YololEmulator/test.lol @@ -1,21 +1,70 @@ -i=:i -o=0 j=0 x="FDB97531" y="FEBA7632" b="B" -c=i---i o+=(4*((c>3)+(c>7)+(c>b))+(x>x-c)+2*(y>y-c))*16^j++ goto 3 +a=:a e=3.934*a^0.228-a^0.319e+=(a<50)*(2.3*a^0.2-e) +b=e-0.5c=e+0.5b*=b>0i=0j=0.001t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b) +t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b)goto3+(i++>9) +w=2^b x=2^(b+j)y=abs(a-w)z=abs(a-x):o=(y<=z)*b+(y>z)*(b+j)goto:done++ +e=3.934*a^0.228-a^0.319e+=(a<50)*(2.3*a^0.2-a) -// 087C9AE93536250F71 -> CHya6TU2JQ9x -// 6B44F9E98541D9612F74DCDD -> a0T56YVB2WEvdNzd -// 867EC75421BB80DD534E143F387CE4 -> hn7HVCG7gN1TThQ/OHzk -// A16EECE36F7991046DD5DB417BD4F52CF9 -> oW7s4295kQRt1dtBe9T1LPk= -// 736BBEEDB8A5AF97898F72C8431E04F494 -> c2u+7bilr5eJj3LIQx4E9JQ= +2.3*:a^0.2 // Worst case 0.5 when :a<50 -## base64 (6 bit) -ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ -## base16 (4 bit) -0123456789ABCDEF +// Worst:0.949 Total:46 +:o=3.934*:a^0.228-:a^0.319 // Worst case 0.1 when :a>50 +// Worst:1.077 Total:214 +:o=3.201*:a^0.177+sqrt(:a)*-0.029 + +// Worst:1.305 Total:315 +:o=3.598*:a^0.143 + +/--------//--------//--------//--------//--------//--------//--------/ + +a=:a e=3.934*a^0.228-a^0.319 b=e-1c=e+1b*=b>0i=0j=0.001 +t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b)goto2+(i++>9) +w=2^b x=2^(b+j)y=abs(a-w)z=abs(a-x):o=(y<=z)*b+(y>z)*(b+j)goto:done++ + +/--------//--------//--------//--------//--------//--------//--------/ + +a=:a e=3.598*:a^0.143b=e-2c=e+2b*=b>0i=0j=0.001 +t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b)goto2+(i++>10) +w=2^b x=2^(b+j)y=abs(a-w)z=abs(a-x):o=(y<=z)*b+(y>z)*(b+j)goto:done++ + +/--------//--------//--------//--------//--------//--------//--------/ + + +a=:a b=0 c=14 i=0 j=0.001 t=(b+c)/2 q=2^t if q>a then c=t else b=t end +t=(b+c)/2 q=2^t if q>a then c=t else b=t end goto2+(i++>11) +w=2^b x=2^(b+j)y=abs(a-w)z=abs(a-x):o=(y<=z)*b+(y>z)*(b+j)goto:done++ + + +/--------//--------//--------//--------//--------//--------//--------/ + +a=:a e=3.598*:a^0.143 b=e-2 c=e+2 b*=b>0i=0 +t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b) goto2+(i++>10) +:o=b goto:done++ + + + +t=(b+c)/2q=2^t if q>a then c=t else b=t end +t=(b+c)/2q=2^t>a c+=q*(t-c)b+=(1-q)*(t-b) +t=(b+c)/2q=2^t>a c+=q--*(t-c)b-=q*(t-b) + +b+=(1-q)*(t-b) +b+=t-b-q*(t-b) +b-=(q-1)*(t-b) + +/--------//--------//--------//--------//--------//--------//--------/ + +:o=3.598*:a^0.143 goto:done++ + +// Total error: 315.896. + +/--------//--------//--------//--------//--------//--------//--------/ + +a=:a b=0 c=14 i=0 +t=(b+c)/2 q=2^t if q>a then c=t else b=t end goto2+(i++>12) +:o=b goto:done++ \ No newline at end of file diff --git a/YololEmulator/warehouse_management.lol b/YololEmulator/warehouse_management.lol new file mode 100644 index 0000000..6947599 --- /dev/null +++ b/YololEmulator/warehouse_management.lol @@ -0,0 +1,25 @@ +w+=:i :o="" r=:r c=r---r:o=c+0+:o-(c+(w-c!=w))w-=c goto2+(r<0) +c=r---r:o=c+0+:o-(c+(w-c!=w))w-=c goto2 +:o=:o-0-0-0-0 goto:done++ + +/--------//--------//--------//--------//--------//--------//--------/ + +w+=:i:i=0c=:r---:r o=(c+0+o-(c+(w-c!=w)))-0w-=c goto1+:r<0 +:o=o o=""goto:done++ + +/--------//--------//--------//--------//--------//--------//--------/ + +w+=:i :o="" r=:r +c=r---r:o=c+0+:o-(c+(w-c!=w))w-=c goto2 +:o=:o-0-0-0-0 goto:done++ + + + + +c=r---r:o=c+0+:o-(c+(w-c!=w))w-=c +c=r---r ifw-c!=w thenw-=c:o=c+:o end + +/--------//--------//--------//--------//--------//--------//--------/ + + +