lang: funcs: core: math: Add a fortytwo function

This is mainly meant as a useful test case, but might as well have it be
fun too. As an aside, it taught me a surprising result about the %v verb
in printf, and we'll have to decide if it's an issue we care about.

https://github.com/golang/go/issues/46118

The interesting thing about this method is that it uses the simplepoly
API but has no input args-- only the output types are different. If it
had identical types in the input args, that might also have been
interesting, but it's more rare to have none. Hopefully this exercises
our type unification logic.
This commit is contained in:
James Shubin
2021-05-12 03:28:19 -04:00
parent fe2b8c9fee
commit b3d1ed9e65
5 changed files with 86 additions and 0 deletions

View File

@@ -379,6 +379,14 @@ func (obj *PrintfFunc) Close() error {
// valueToString prints our values how we expect for printf.
// FIXME: if this turns out to be useful, add it to the types package.
func valueToString(value types.Value) string {
switch x := value.Type().Kind; x {
// FIXME: floats don't print nicely: https://github.com/golang/go/issues/46118
case types.KindFloat:
// TODO: use formatting flags ?
// FIXME: Our String() method in FloatValue doesn't print nicely
return value.String()
}
// FIXME: this is just an "easy-out" implementation for now...
return fmt.Sprintf("%v", value.Value())