× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Pay attention to MOD ( was int(-8.9)=-9 or -8)
  • From: "Jim" <jcannon@xxxxxxxxxxx>
  • Date: Thu, 2 Mar 2000 08:33:07 -0700

NOW I understand! LOL

Date sent:              Thu, 02 Mar 2000 11:31:18 +0900
From:                   "Tadashi K." <tadashii@tk.airnet.ne.jp>
To:                     RPG400-L@midrange.com
Subject:                Re: Pay attention to MOD ( was int(-8.9)=-9 or -8)
Send reply to:          RPG400-L@midrange.com

Hi, all

I'm glad to receive a lot of advices. Thank you so much indeed.

And I want to explain why I posted such message. This will be a caution for
the programmers (maybe <g>).

I introduced the Zeller's formula as a column of computer tips in my home
page for Japanese programmers. (Of course I know there is a function for
calculation of the day of week in RPG iv.)

Zeller's formula is known as below. There are two types. 
        (I) (yy2+[yy2/4]+[yy1/4]+[26(mm+1)/10]-(2*yy1)+dd)mod 7 
        (II) (yyyy+[yyyy/4]-[yyyy/100]+[yyyy/400]+[(2.6*mm)+1.6]+dd) mod 7
(In Jan. and Feb. mm must be 13,14 in the last year).

On March 1st,2000 one visitor asked 'The formula (I) returned a wrong data,
is this a kind of Y2K problem?'

?Y2K? Zeller's formula is an official one, there must be no problem.
I uploaded the EXCEL example and I showed it worked correctly for him.

But, the other visitor asked me again 'Why does (-24) mod 7 come to 4? Please
explain it.'

I was confused.

February 29th,2000 = 99+[99/4]+[19/4]+[26(14+1)/10]-(2*19)+29) mod 7
        =(99+24+4+39-38+29)mod 7=(157) mod 7= 3 (=Tuesday)

March 1st,2000 = 00+[00/4]+[20/4]+[26(3+1)/10]-(2*20)+1) mod 7  
        =(00+00+5+10-40+1)mod 7=(-24) mod 7= 4 (=Wednesday)

Certainly I could get the day of week, so it seemed to work well. 
BUT, what was mod(-24,7)=4 ??? I felt it strange. 
The RPG code (DIV and MVR) returned -3.(i.e. -24-(-3 *7)=-24+21=-3).

When I saw the help text of the MOD function in Excel, I was surprised.
In the help of mod it says,

        MOD(n,d) = n - d*INT(n/d)
        <Examples>
        MOD(3,2) = 1
        MOD(-3,2) = 1  <===

Hey! Why mod(-3,2)=1??? I think it must be -1.

Oh, IIIII Seeeee. INT is in there! Can you see the 'INT' in MOD(n,d) above? 
And in the help of INT,it says INT(8.9)=8, INT(-8.9)= -9.
So, now I can see why MOD(-3,2)=1, and MOD(-24,7)=4.

        MOD(-3,2)=-3-2*INT(-3/2)=-3-2*INT(-1.5)=-3-2*(-2)=-3+4=1.
        MOD(-24,7)=-24-7*INT(-24/7)=-24-7*INT(-3.4)=-24-7*(-4)=-24+28=4.

It still seems a strange thing for me. Can you accept this result?

That's why I posted my message.

After I posted the message, I checked the book of an algorithm of C language,
and I knew there were some functions, named FLOOR,or CEILING.
        floor(2.718)=2, floor(-2.718)=-3
        ceiling(2.718)=3, ceiling(-2.718)=-2 
If these functions are real one, INT behaves like FLOOR. 
BTW, what is floor or ceiling for ? I don't know C Language well. I bought
the book of an algorithm of C as my pillow <g>.

Anyway, I use often the EXCEL as a debugging tool (for confirmation of the
result of programs that I made). 
And you should pay attention to 'negative numbers in MOD or INT' in EXCEL.

*------------*-------------*--------------*

I'm sorry for my poor English, do you make out what I mean? I'm uncertain of
it. All I can do it here is just a spell-checking.

HTH

Best regards.

On Wed, 01 Mar 2000 21:53:30 +0900
"Tadashi K." <tadashii@tk.airnet.ne.jp> wrote in "int(-8.9)=-9 or -8":

  > Hi, all
  > 
  > By Excel functions, int(-8.1)=-9. And %Int in RPGiv is -8. 
  > 
  > How can I get -9 same as an Excel function by RPG iv?
  > Is which result(-9 or -8) normal for you ?
  > 
  > Tadashi
  > 
  > /* ---------------------------------------------------------*/
  >                        Tadashi Kakefuda
  >  The Internet Mail Address ; tadashii@tk.airnet.ne.jp
  >    * Official site ; http://www2c.airnet.ne.jp/as400/
  >  /*----------------------------------------------------------*/
  > +---
  > | This is the RPG/400 Mailing List!
  > | To submit a new message, send your mail to RPG400-L@midrange.com.
  > | To subscribe to this list send email to RPG400-L-SUB@midrange.com.
  > | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
  > | Questions should be directed to the list owner/operator: 
david@midrange.com
  > +---
  > 


T.I.A.

Best regards.

/* ---------------------------------------------------------*/
                       Tadashi Kakefuda
 The Internet Mail Address ; tadashii@tk.airnet.ne.jp
   * Official site ; http://www2c.airnet.ne.jp/as400/
 /*----------------------------------------------------------*/
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.