If you just want a lexically scoped different behavior for / you can do
something like this:

julia> baremodule IntegerDivision
         export /
         import Base
         /(x::Number, y::Number) = Base./(x,y)
         /(x::Integer, y::Integer) = Base.div(x,y)
       end

julia> baremodule Foo
         using Base, IntegerDivision
         @show 2 / 3
         @show 2 + 3
       end
2 / 3 => 0
2 + 3 => 5


It's a little bit awkward to do, but I'm not sure doing this is really a
good idea anyway.


On Fri, Apr 4, 2014 at 11:54 AM, Carlos Becker <carlosbec...@gmail.com>wrote:

> I don't see that as a viable option either.
> I am trying to find out which other operations would do such promotion,
> but so far the relevant one seems to be only division, I can handle that.
>
> Now, in terms of hypothetical workarounds, what about having a macro to
> override type promotion? Would that make sense? I don't know Julia
> internals, but would this be difficult to implement?
> Of course, in such case operations must happen between elements of the
> same (scalar) type, otherwise it should throw an error.
>
>
> ------------------------------------------
> Carlos
>
>
> On Fri, Apr 4, 2014 at 5:42 PM, Stefan Karpinski <ste...@karpinski.org>wrote:
>
>> The change you want would be a one-line change:
>>
>> https://github.com/JuliaLang/julia/blob/master/base/int.jl#L50
>>
>> However, that change would affect all code using division of integers,
>> which seems likely to wreak havoc. As others have pointed out, the operator
>> for truncated integer division is div; the operator for floored integer
>> division is fld.
>>
>>
>> On Fri, Apr 4, 2014 at 5:09 AM, Carlos Becker <carlosbec...@gmail.com>wrote:
>>
>>> I've seen previous posts in this list about this, but either I missed
>>> some of them or this particular issue is not addressed. I apologize if it
>>> is the former.
>>>
>>> I have a Uint8 array and I want to divide (still in Uint8) by 2. This is
>>> very handy when dealing with large images: no need to use more memory than
>>> needed.
>>> So, for example:
>>>
>>> A = rand(Uint8, (100,100));   # simulated image
>>>
>>> b = A / uint8(2)
>>>
>>> typeof( b )  # ==> returns Array{Float32,2}
>>>
>>>
>>> I understand why one may want that, but is there a way to override it
>>> and do the plain, element-wise uint8-by-uint8 division?
>>> (ie ignore promotion rules)
>>>
>>> Thanks.
>>>
>>
>>
>

Reply via email to