Re: [api-dev] Integer Division?

2005-12-14 Thread Christian Junker
The thing I don't understand is why this special operator even exists,
since I have never seen the "\" operator before. And so the question
is what 11/3 should really return. I don't know what it returns in
VisualBasic (since SB should resemble VB), but I would rather like to
have it the C way.

There is also an open issue on this, it would love to get some more
attention I guess ;-).
http://qa.openoffice.org/issues/show_bug.cgi?id=51219

2005/12/14, Laurent Godard <[EMAIL PROTECTED]>:
> Hi Felix,
>
> > How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?
>
> try this
> 11 \ 3 = 3
> or fix(11/3)
>
> the rounding depends of what you need
> for me 11/3 is rounded to 3
>
> Laurent

--
Best Regards
Christian Junker

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Andrew Douglas Pitonyak

Felix E. Klee wrote:


Am Mittwoch, 14. Dezember 2005 12:11 schrieb Laurent Godard:
 


11 \ 3 = 3
   



I couldn't find documentation for this operator in the online help (1.1.3).  
How come?


 


or fix(11/3)
   



Well this probably uses a floating point number as an intermediary, which 
could introduce numerical errors.  This is not what I want.


Anyway, thanks for your help so far.
 

I believe that it is not documented. I documented them in my book by 
reading the source code


--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info:  http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Dieter Krogh - Sun Germany

Hi Felix,

does

   Dim iResult as integer
   iResult = 11 \ 3

fit your needs?

The "\" operator would do the division with a whole number result.

BTW, 11 / 3 would never result as "4". ;-)

Best wishes
Dieter

Felix E. Klee wrote On 12/14/05 11:26,:

How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?



--

  Dieter Krogh
  Support Engineer RSD StarOffice/Linux/Cobalt EMEA

  Sun Services   Tel:  (+49 40) 23646-744 / x66744
  Sun Microsystems GmbH  Fax:  (+49 40) 23646-750
  Sachsenfeld 4  http://www.sun.de
  D-20097 Hamburgmailto:[EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Felix E. Klee
Am Mittwoch, 14. Dezember 2005 12:21 schrieb Joerg Barfurth:
> >> How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice
> >> Basic?
>
> Huh? IME the integer division operator (in languages where it exists)
> would produce 11 div 3 = 3, to match the modulus produced by the 'mod'
> operator (which does exist in StarBasic).

Whoah, a fatal typo.  Here's what I should've written: 11/3 = 3.

> You can get a more typical integer division by using the available
> functions to convert to an integer by rounding down or truncating
>
>   roundeddown% = int(11/3) ' value is 3
>   truncated% = fix(11/3)   ' value is 3
>
> These differ when negative numbers are involved. AFAICT truncation is
> the one that matches the builtin MOD operator, ie.
>
>b*fix(a/b) + a mod b = a

Well, I guess that all of these use floating point numbers as an intermediary, 
something I do *not* want.

-- 
Dipl.-Phys. Felix E. Klee
Email: [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (home)
Tel: +49 721 8307937, Fax: +49 721 8307936
Linuxburg, Goethestr. 15A, 76135 Karlsruhe, Germany

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Felix E. Klee
Am Mittwoch, 14. Dezember 2005 12:11 schrieb Laurent Godard:
> 11 \ 3 = 3

I couldn't find documentation for this operator in the online help (1.1.3).  
How come?

> or fix(11/3)

Well this probably uses a floating point number as an intermediary, which 
could introduce numerical errors.  This is not what I want.

Anyway, thanks for your help so far.

-- 
Dipl.-Phys. Felix E. Klee
Email: [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (home)
Tel: +49 721 8307937, Fax: +49 721 8307936
Linuxburg, Goethestr. 15A, 76135 Karlsruhe, Germany

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Joerg Barfurth

Hi,

How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice 
Basic?




Huh? IME the integer division operator (in languages where it exists) 
would produce 11 div 3 = 3, to match the modulus produced by the 'mod' 
operator (which does exist in StarBasic).


That said, you can get the behavior you want (rounding) by assigning the 
result of a plain division to an integer variable


  q% = 11/3 ' Now the value of q% is 4

You can get a more typical integer division by using the available 
functions to convert to an integer by rounding down or truncating


 roundeddown% = int(11/3) ' value is 3
 truncated% = fix(11/3)   ' value is 3

These differ when negative numbers are involved. AFAICT truncation is 
the one that matches the builtin MOD operator, ie.


  b*fix(a/b) + a mod b = a

HTH, Joerg


--
Joerg Barfurth  Sun Microsystems - Desktop - Hamburg
>> using std::disclaimer <<<
Software Engineer [EMAIL PROTECTED]
OpenOffice.org Configuration  http://util.openoffice.org


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Paolo Mantovani
hi Felix

Alle 11:26, mercoledì 14 dicembre 2005, Felix E. Klee ha scritto:
> How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?

in basic there is a \ operator (perhaps not documented)
but the result is rounded to the lower integer.

Anyway you can write your own function for rounding numbers, like the 
following (not tested!! I wrote it directly on the mail-client :-)

regards
Paolo M

8<---

Sub Test
  Print RoundIt(11/3)
End Sub

Function RoundIt(Number) As Integer
Dim dDelta As Double
  dDelta = Number - Int(Number)
  If dDelta  > 0.5 Then
RoundIt = Int(Number) + 1
  Else
RoundIt = Int(Number)
  End If
End Function

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Stephan Wunderlich - Sun Germany - ham02 - Hamburg

Hi Felix,


http://www.richhillsoftware.com/blog/archives/2005/06/xnumbers_011_no.html



Do I really need an extra package just to do integer division?  This operation 
is built into almost every programming language!


does

   print cint(11/3)

do what you want ?

Regards

Stephan

--
Everything should be made as simple as possible, but
not one bit simpler. Albert Einstein (1879 - 1955)

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Laurent Godard

Hi Felix,


How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?


try this
11 \ 3 = 3
or fix(11/3)

the rounding depends of what you need
for me 11/3 is rounded to 3

Laurent

--
Laurent Godard <[EMAIL PROTECTED]> - Ingénierie OpenOffice.org
Indesko >> http://www.indesko.com
Nuxeo CPS >> http://www.nuxeo.com - http://www.cps-project.org
Livre "Programmation OpenOffice.org", Eyrolles 2004

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Eric MOREL




No I don't think so but perhaps you can see the macro code behind Xdivint().


Eric

Felix E. Klee a écrit :

  Am Mittwoch, 14. Dezember 2005 11:39 schrieb Eric MOREL:
  
  
http://www.richhillsoftware.com/blog/archives/2005/06/xnumbers_011_no.html

  
  
Do I really need an extra package just to do integer division?  This operation 
is built into almost every programming language!
  




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Felix E. Klee
Am Mittwoch, 14. Dezember 2005 11:39 schrieb Eric MOREL:
> http://www.richhillsoftware.com/blog/archives/2005/06/xnumbers_011_no.html

Do I really need an extra package just to do integer division?  This operation 
is built into almost every programming language!

-- 
Dipl.-Phys. Felix E. Klee
Email: [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (home)
Tel: +49 721 8307937, Fax: +49 721 8307936
Linuxburg, Goethestr. 15A, 76135 Karlsruhe, Germany

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Integer Division?

2005-12-14 Thread Eric MOREL

Hi,

Do you know this 
:http://www.richhillsoftware.com/blog/archives/2005/06/xnumbers_011_no.html


Eric

Felix E. Klee a écrit :


How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?

 




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[api-dev] Integer Division?

2005-12-14 Thread Felix E. Klee
How do I perform an integer division (e.g. 11 / 3 = 4) in OpenOffice Basic?

-- 
Dipl.-Phys. Felix E. Klee
Email: [EMAIL PROTECTED] (work), [EMAIL PROTECTED] (home)
Tel: +49 721 8307937, Fax: +49 721 8307936
Linuxburg, Goethestr. 15A, 76135 Karlsruhe, Germany

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]