diff --git a/src/gates/AmplitudeDisplay.js b/src/gates/AmplitudeDisplay.js index cf89fb6a..a2faef91 100644 --- a/src/gates/AmplitudeDisplay.js +++ b/src/gates/AmplitudeDisplay.js @@ -182,7 +182,7 @@ const SPREAD_LENGTH_ACROSS_POLAR_KETS_SHADER = makePseudoShaderWithInputsAndOutp uniform float bit; float xorBit(float v) { - float b = mod(floor(v/bit), 2.0); + float b = floor(mod(floor(v/bit) + 0.5, 2.0)); float d = 1.0 - 2.0*b; return v + bit*d; } @@ -257,7 +257,7 @@ const TO_RATIOS_VS_REPRESENTATIVE_SHADER = makePseudoShaderWithInputsAndOutputAn ], Outputs.vec4(), `vec4 outputFor(float k) { - return vec4(read_ket(k), read_rep(mod(k, len_rep())).xy); + return vec4(read_ket(k), read_rep(floor(mod(k + 0.5, len_rep()))).xy); }`); /** diff --git a/src/gates/ModularAdditionGates.js b/src/gates/ModularAdditionGates.js index 18b84098..29248570 100644 --- a/src/gates/ModularAdditionGates.js +++ b/src/gates/ModularAdditionGates.js @@ -33,16 +33,8 @@ const MODULAR_ADDITION_SHADER = ketShaderPermute( } float d = read_input_A(); d *= factor; - d = mod(d, r); - float result = mod(out_id + r - d, r); - - // Despite sanity, I consistently get result=33 instead of result=0 when out_id=0, d=0, r=33. - // HACK: Fix it by hand. - if (result >= r) { - result -= r; - } - - return result; + d = floor(mod(d + 0.5, r)); + return floor(mod(out_id + r - d + 0.5, r)); `); ModularAdditionGates.PlusAModRFamily = Gate.buildFamily(1, 16, (span, builder) => builder. diff --git a/src/gates/MultiplyAccumulateGates.js b/src/gates/MultiplyAccumulateGates.js index 933739b1..e5f7f2d0 100644 --- a/src/gates/MultiplyAccumulateGates.js +++ b/src/gates/MultiplyAccumulateGates.js @@ -44,10 +44,10 @@ const BIG_MUL_MOD_SHADER_CODE = ` float t = 0.0; float r; for (int k = 0; k < ${Math.ceil(Config.MAX_WIRE_COUNT/MUL_STEP)}; k++) { - r = mod(f, ${1< { let output = BOOL_TYPE_CODER.outputPart; let shader = combinedShaderPartsWithCode([output], ` bool outputFor(float k) { - return mod(k, 3.0) == 1.0; + return floor(mod(k + 0.5, 3.0)) == 1.0; }`); assertThat(shaderWithOutputPartAndArgs(shader, output, []).readBoolOutputs(3)).isEqualTo(new Uint8Array([