Skip to content

math/big: support for long arithmetic #890

@tucnak

Description

@tucnak

Hello again,

According to language support page, much of the crypto functionality of Go is currently unavailable, and math/big seems to be the culprit.

Packages like crypto/tls also rely on net, which I belive won't be trivial to get right due to concurrency, but the elliptic crypto packages, as well as encoding/asn1 among others, are not accessible exclusively due to one math/big bug:

# math/big
../../../../../../../usr/local/Cellar/go/1.13.7/libexec/src/math/big/float.go:559:4: interp: branch on a non-constant

I've pulled the relevant code, but I'm yet to realise what's the branch in question. Look:

func (z *Float) SetFloat64(x float64) *Float {
	if z.prec == 0 {
		z.prec = 53
	}
	if math.IsNaN(x) {
		panic(ErrNaN{"Float.SetFloat64(NaN)"})
	}
	z.acc = Exact
	z.neg = math.Signbit(x) // handle -0, -Inf correctly
	if x == 0 {
		z.form = zero
		return z
	}
	if math.IsInf(x, 0) {
		z.form = inf
		return z
	}

	// normalized x != 0

/*-->*/	z.form = finite // line 559

	fmant, exp := math.Frexp(x) // get normalized mantissa
	z.mant = z.mant.setUint64(1<<63 | math.Float64bits(fmant)<<11)
	z.exp = int32(exp) // always fits
	if z.prec < 53 {
		z.round(0)
	}
	return z
}

I've only gone as far as to check finite, only to realise it's a const form iota, which is a byte-sized description of some internal representation. This code looks totally regular. Any ideas why this could go wrong? I desperately need small wasm binaries for my crypto stuff, and would love to figure this one out, but at this moment of time it's well out of my expertise.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions