小企鵝輸入法(FCITX)·仿極點五筆特殊符號輸入編碼表
Common Lisp常用輔助工具

rem和mod的區別

λ posted @ 2011年12月06日 18:27 in Mixture with tags lisp tutorial , 6749 阅读

我不清楚remmod兩種運算是否遵從什麼標準,也不瞭解它們從何而來,不過對於LISP來說,它是有標準的就OK了。它們對負數的運算方式也不難記憶,在此我只是提供一種記憶的方法。

細說rem&mod(remainder&modulo)

大家先來回顧一下小學學過的除法運算,被除數除以除數,得到商和餘數(只考慮整數運算):

a ÷ b = q … r

r = a - q × b

而取模運算,就是只要得到那個餘數r就可以了。

其實要記憶好remmod處理負數時的區別,也要考慮下那個商q的。正負相除得負,負負相除得正,這就是得到q的規律。r是最後才來確定的。下面就開始講解remmod吧。

rem:使商向「內」取整

向「內」取整是什麼意思呢?就是指讓商的絕對值儘量小,就像用truncate函數把不求餘的商的絕對值的小數部分截掉一樣。就舉例說明吧:

7 ÷ 3 ≈ 2.3

7 rem 3 = 2 … 1

7 rem -3 = -2 … 1

-7 rem 3 = -2 … -1

-7 rem -3 = 2 … -1

明白了吧?我就不廢話了。

mod:使商向「下」取整

向「下」取整即讓商的值儘量小(不是說絕對值),如經過floor函數處理一樣。例:

7 ÷ 3 ≈ 2.3

7 mod 3 = 2 … 1

7 mod -3 = -3 … -2

-7 mod 3 = -3 … 2

-7 mod -3 = 2 … -1

OK,解說完畢。

其它資料

或許大家已經發現,對於rem來說,餘數的符號與被除數的相等,而mod的則是與除數相等。

另外可到此處瞭解:http://www.franz.com/support/documentation/8.1/ansicl/dictentr/modrem.htm


本網站無註明「轉載」的著作均由Jak Wings製作 CC BY-NC-SA 2.5
Creative Commons 保持署名-相同方式分享 2.5

Avatar_small
Rrandom 说:
Dec 07, 2011 10:18:11 PM

racket里
分别叫做remainder和modulo
> (remainder 1 3)
1
> (modulo 1 -3)
-2
> (remainder 1 -3)
1

remainder叫做取余.modulo叫做取模...

Avatar_small
λ 说:
Dec 07, 2011 11:12:21 PM

-_-;感覺都一個意思,「模」好像是mo的擬聲。Racket竟然會用這麼完整的名稱啊……嗯,從結果看來,是同一標準的。

HDFC CIBIL score 说:
Aug 06, 2022 10:42:58 PM

Before we show you how you can check CIBIL score, first know that TransUnion CIBIL is an organization and an entity gathers all the consumer’s loan, credit, payment and money related transaction, and this gives a general behavior example and statics allowing to generate a score for each customer also calls as CIBIL score. In simple words, every individual based on their payment choices, credit decisions and money pertains may rank and given CIBIL score points which range up to 900 points. In the sense, if the customer receives anything above 750 – 900, <a href="https://25penny.com/cibil-score-login-check-report-free-paid/">HDFC CIBIL score</a> then they have high credit affinity. With this the banks and loan facilities may happy to lend credit to them. But in case if the CIBIL score for you is anywhere less than 750 or even worse then there are high chances that you will reject any loans, EMI, or credit requests. Because loan facilities and banks would consider your CIBIL Score as a baseline for approving those requests.

NCERT Sanskrit Sampl 说:
Sep 19, 2022 01:24:53 AM

The Sanskrit Language is one of the important languages and those 2nd Standard students of English Medium, Hindi Medium and Urdu Medium crossed it as their Second or Third Language. The Sanskrit language helps students to about the Indian culture and history of our country etc. So students who chose the Sanskrit language as their optional language can download NCERT Sanskrit Sample Paper 2023 Class 2. NCERT Sanskrit Sample Paper Class 2 Learning the Sanskrit language should begin from the foundation of Education to enable students to understand the language without any difficulties. To know the examination question pattern and scheme of the exam everyone can download NCERT Sanskrit Sample Paper 2023 Class 2 for all formats of exams conducted in Term 1, and Term 2.

Previous Paper 2024 说:
Feb 11, 2023 05:56:39 PM

Previous Paper 2024 Every one of the students are right now sitting tight for the test Model Paper to be Download, so need to reveal to you that as per the data got from the sources as of late, Previous Paper 2024 The board will deliver its Question Paper, realizing that it will be made accessible to you. Board of Secondary Education is otherwise called The Educational board leads secondary school and transitional board tests each year.

jnanabhumiap.in 说:
Apr 25, 2023 02:32:16 PM

We provide you the finest of web content on each and every topics possible with help of editorial and content team.Jnanabhumi AP is a startup by passionate webmasters and bloggers who have passion to provide engaging content which is accurate, interesting and worthy to read. We are mope like a web community where you can jnanabhumiap.in find different information’s, resources, topics on day to day incidents or news.

Haryana 10th Class 说:
Aug 15, 2023 03:28:35 PM

HBSE High School Students can Download the Textbooks for Academic Education Study Further uses, we have given more information about the Haryana Board Class Book 2024, This Study Meterial Prepare by SCERT Haryana Board Senior Experts,Haryana 10th Class Books Should be Followed as the Prime Resource Throughout the year to Clear All Doubts and Strengthen your knowledge. HBSE Class Haryana 10th Class Books 2024 Textbook 2024 Provides an easy Explanation for Various Concepts in the Curriculum. Our Portal are Providing the Latest Version of Haryana Book 2024 which is Published by the State Council of Education Research.

seo service london 说:
Jan 16, 2024 10:57:58 PM

I just thought it may be an idea to post incase anyone else was having problems researching but I am a little unsure if I am allowed to put names and addresses on here


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter