On Mon, Sep 29, 2014 at 4:27 PM, Kishore Kumar Vaishnav
<kishore...@gmail.com> wrote:
>
> a) I am not able to do modulus on the float types, it reports the below
> statement
> invalid operation: c % d (operator % not defined on float32)
> I feel that modulus should not be restricted on int but should be allowed to
> be done on float too. Is this a bug to be filed? If not, why?
I don't know of any sensible definition of the modulos operation on
floating point values. What should it evaluate to.
> b) I am trying to use the below line
> fmt.Printf(" a % b : %d", a%b)
> instead of printing the desired output
> a % b : 3
> it prints the below output
> a 11 : %!d(MISSING)
> So I tried to escape with \ but it didn't worked as it generally work for
> the other characters when we do escaping. But what I found interesting is
> that it escapes % with % itself.
> fmt.Printf(" a \" % b : %d", a%b) // a " % b : 3
> fmt.Printf(" a %% b : %d", a%b) // a % b : 3
> Is this what expected? Or Go is missing something?
This is working as intended. When using fmt.Printf you introduce
formatting directives with %. The %% formatting directive prints as
"%". There is no need to also support backslash escaping, which is a
good thing because backslashes are evaluated when parsing string
literals.
C's printf function behaves the same way.
Ian
On Mon, Sep 29, 2014 at 4:27 PM, Kishore Kumar Vaishnav
<kishore...@gmail.com> wrote:
>
> a) I am not able to do modulus on the float types, it reports the below
> statement
> invalid operation: c % d (operator % not defined on float32)
> I feel that modulus should not be restricted on int but should be allowed to
> be done on float too. Is this a bug to be filed? If not, why?
I don't know of any sensible definition of the modulos operation on
floating point values. What should it evaluate to.
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks I found this earlier too
, do you remember any float32 modulus function. Looks like its not present, is it something which is intentionally not done for some reason?