1. integer division

I download Euphoria 1.5a and a tutorial yesterday.  Now I have a question:
Does Euphoria have a version of the Qbasic "\" operator?  Also, one thing
that I've never found in any language, even Euphoria, is a way to create a
user-defined operator.

new topic     » topic index » view message » categorize

2. Re: integer division

Andrew Nagy asked:
> Does Euphoria have a version of the Qbasic "\" operator?

To perform integer division in Euphoria use something like:

       z = floor(x/y)

This will give you a result that is rounded down to an integer.
I don't know if it's exactly compatible with QBasic for negative
numbers. It looks like it would be slower than a normal divide,
but actually floor(x/y) is faster than x/y.

> Also, one thing
> that I've never found in any language, even Euphoria, is a way to create a
> user-defined operator.

You can do it in C++, but I think it leads to unreadable code.
e.g. you might extend the meaning of the "+" or "-" symbols.

Regards,
  Rob Craig
  Rapid Deployment Software

new topic     » goto parent     » topic index » view message » categorize

3. Re: integer division

On Wed, 3 Sep 1997, Andrew Nagy wrote:

> Subject:      integer division
>
 -------------------------------------------------------------------------------
>
> I download Euphoria 1.5a and a tutorial yesterday.  Now I have a question:
> Does Euphoria have a version of the Qbasic "\" operator?  Also, one thing
> that I've never found in any language, even Euphoria, is a way to create a
> user-defined operator.

Creating user-defined operators is routinely done in Forth. If that's what
you need, just get one of several public domain Forths from the
Internet and create as many operators you need.

S.

new topic     » goto parent     » topic index » view message » categorize

4. Re: integer division

At 14:57 03/09/97 -0400, you wrote:
>---------------------- Information from the mail header -----------------------
>Sender:       Euphoria Programming for MS-DOS <EUPHORIA at
>MIAMIU.ACS.MUOHIO.EDU>
>Poster:       Andrew Nagy <WerdnA309 at AOL.COM>
>Subject:      integer division
>-------------------------------------------------------------------------------
>
>I download Euphoria 1.5a and a tutorial yesterday.  Now I have a question:
>Does Euphoria have a version of the Qbasic "\" operator?

Not needed.

Example:

print(1,msg)  puts(1"hello")  mynum=mynum+4  myfile=open("myfile","r")

This should work. Please correct me if I'm wrong.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The Reaper  (J. Lays)   http://www.geocities.com/TimesSquare/Alley/4444/
reaper at auracom.com      Check out my Euphoria Games page at:
            -= http://www.geocities.com/TimesSquare/Alley/4444/eugames.html
      ........................
     . .. -||..........__......  "Some will live life
      . /  ||......../-- \\.::::  Unwilling to ask why,
   . ..|   ||...... /    | |.:::  And they will be forgotten,
     .|  _-||.......||   / /.:::: After they die."
    ..| |..||...... -\_- \ |\-.:::
     .| |.[< \ .../            \.::
      .||.|||\|\ |  -      - .  \.::::
     ...|.\|| |  \  |        |   |.:::.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

new topic     » goto parent     » topic index » view message » categorize

5. integer division

>I download Euphoria 1.5a and a tutorial yesterday.  Now I have a
>question: Does Euphoria have a version of the Qbasic "\" operator?

Integer division is faster than floating point, obviously. But wouldn't
the interpreter have to verify that both values are integers, and then
convert them if they aren't? It seems to me that this would take longer
than just doing a floating-point divide. Especially on today's
processors that are so floating-point enhanced. Can anyone explain this
to me.

At any rate a forced integer divide would be out of place in Euphoria.
It would return us to thinking about our individual numbers as integer,
floats, longs, etc... The great thing about Euphoria is that it allows
you to ignore such isses, unless you are doing power programming (read:
games). Also, I am sure that the processor requires integer values for
the operands in such as function, so the Euphoria interpreter will still
need to check (and possibly convert) the atoms to see if they are
integers.

Of course maybe all you want is to do a integer-divide for the sake of
getting just integers. In that case...

        function int_divide(atom operand1, atom operand2)
                return floor(operand1/operand2)
        end function

This is probably not that fast, but it does give a result that is always
an integer.

John DeHope

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu