FAQ
Hello

I am wondering when is aliasing arguments and the result allowed with
math/big?

The current code seems to explicitly take aliasing into consideration,
but according to a comment in issue 7814 "the program uses the same Int
for result and arguments, so the behavior is undefined." aliasing should
not be used.

Take for example http://play.golang.org/p/wUGP39gbyy
What is the current best practice for writing it?

What operations are defined and undefined with respect to aliasing?

- Taru Karttunen

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jan Mercl at Apr 20, 2014 at 10:30 am

    On Sun, Apr 20, 2014 at 11:58 AM, Taru Karttunen wrote:
    What operations are defined and undefined with respect to aliasing?
    """"
    Methods are typically of the form:

    func (z *Int) Op(x, y *Int) *Int (similar for *Rat)

    and implement operations z = x Op y with the result as receiver; if it
    is one of the operands it may be overwritten (and its memory reused).
    """"[0]

       [0]: http://golang.org/pkg/math/big/#pkg-overview

    -j

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Minux at Apr 20, 2014 at 6:04 pm

    On Sun, Apr 20, 2014 at 5:58 AM, Taru Karttunen wrote:

    I am wondering when is aliasing arguments and the result allowed with
    math/big?

    The current code seems to explicitly take aliasing into consideration, but
    according to a comment in issue 7814 "the program uses the same Int for
    result and arguments, so the behavior is undefined." aliasing should not be
    used.

    Take for example http://play.golang.org/p/wUGP39gbyy
    What is the current best practice for writing it?
    Sorry, I was wrong about the undefined behavior. The behavior is well
    defined.

    I’d say for simple operations that it's possible to do inline, using the
    same argument for
    input and output is preferable; but for complex operations like Exp where
    it's a not possible
    to directly do inline operation on the result, using aliased argument and
    result will result in
    math/big make a copy and then do the assignment, so it's not ideal in this
    case.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 20, '14 at 9:59a
activeApr 20, '14 at 6:04p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase