ぽざうねっと

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  420  : 記事  0  : コメント  9422  : トラックバック  76

ニュース

さて、今年は何を漬けようか

書庫

日記カテゴリ

Accessory

Community

Private

Ruby でも多くの言語のように剰余が求められるのだが、動きが異なるので注意が必要。
5 % 3 → 2
-5 % 3 → -2
5 % -3 → 2
-5 % -3 → -2
C#, Java, JavaScript, XSLT あたりで確認したけど、ほとんどはこうらしい。
んで、Ruby はこうなる。
5 % 3 → 2
-5 % 3 → 1
5 % -3 → -1
-5 % -3 → 2
負数の剰余なんて使う機会はあまりないけど。
投稿日時 : 2008年6月24日 21:52

コメント

# re: Ruby の剰余にご用心 2008/06/24 22:50 出水
正規化とかで結構使いますよー
後ろの数が負になることは少ないけど
前の数が負になることはしょっちゅう

常に答えが正になる剰余が欲しいところです

# re: Ruby の剰余にご用心 2008/06/25 11:33 凪瀬
実用上はRuby側の方が使いやすいかもなぁ。
数学的な剰余だと0寄りに余りを求めるんだったような。でも、ロジック上は0で切り替わられてもあんまり嬉しくない

# re: Ruby の剰余にご用心 2008/06/25 23:45 THREE-ONE
>出水さん
正規化ですか。
いつか使うときのために覚えておきます。

>凪瀬さん
wikipedia いわく、どちらの流儀もあるらしいです。
数学のくせに流儀で答えが違うとかよくわかりません。

# re: Ruby の剰余にご用心 2008/06/27 0:59 ゆう
負数の除算、剰余は処理系依存なんですね。
今まで、C#/Javaの計算結果が当然だと思っていたので衝撃を受けました。

私の場合、剰余はあまり気にすることがなかったので、
除算の結果が異なることにことにですが。
# Rubyでは、5 / -3 → -2

Rubyのリファレンスマニュアルによると、剰余に関しては
remainderメソッドを使うとC#/Javaと同じ結果になるそうです。
http://www.ruby-lang.org/ja/man/html/Numeric.html#modulo
# 5.remainder(-3) → 2

# re: Ruby で数値を 0 埋めする 2019/01/24 13:57 zzyytt
http://www.nhljerseysshop.us.com
http://www.airjordanretro.uk
http://www.yeezy-boosts.us.com
http://www.hermes-belt.us.com
http://www.birkinbag.us.com
http://www.michael--korsoutlet.us.org
http://www.kevindurant-shoes.us.com
http://www.calvinkleinoutlet.us.com
http://www.mbtshoesonline.com
http://www.shoesjordan.us.com
http://www.hermes-handbags.us.com
http://www.goldengoosesneakers.us
http://www.yeezyboost350v2.org.uk
http://www.nikeflyknit.us.com
http://www.jordansforcheap.us.com
http://www.canada-goose.in.net
http://www.yeezysshoes.us.com
http://www.goldengoose.us.com
http://www.balenciaga.us.com
http://www.airmax270.us.com


# re: Ruby で数値を 0 埋めする 2019/01/24 14:06 zzyytt
http://www.outletlacoste.us.com
http://www.adidas-pureboost.us.com
http://www.coachoutlets.name
http://www.kd11.us.com
http://www.cheap-airjordans.us.com


# Vapor Max 2019/05/02 19:19 uqvnrdp@hotmaill.com
For several minutes, the Portland Trail Blazers’ star guard sat quietly on his sofa, chowing down on fried catfish, red beans and rice, and broccoli. And then suddenly, he spoke: I’m getting rid of these mother------- tomorrow.

# NFL Jerseys 2019/05/07 9:34 myincwcbi@hotmaill.com
Traditionally, both professional and collegiate teams are invited to celebrate with the President at the White House after winning a championship. Under the Trump administration, however, this has not always been the case. Several teams, both collegiate and professional, have either declined invitations or have not been invited at all.

# nike factory outlet store online 2019/05/10 3:31 rksuuzxxb@hotmaill.com
But through this reluctant and unexpected admittance into the world of infertility, I have learned the value of striving toward hope; it may come without the guarantee of reward. I’ve had to turn my dream over to science. But I now know that whatever the future brings, I will be grateful for every moment.

# Nike Shoes 2019/05/12 15:07 gjtbwir@hotmaill.com
There are now three, with Rep. Tim Ryan of Ohio joining on April 4, Rep. Eric Swalwell of California entering on April 8 and Rep. Seth Moulton of Massachusetts officially declaring on April 22.

# NFL Jerseys 2019/05/15 18:07 ghiwdu@hotmaill.com
http://www.pandoraoutlet-jewelry.us/ pandora jewelry outlet

# Travis Scott Air Jordan 1 2019/06/07 11:36 hqjspktqtu@hotmaill.com
Raja's wife and other relatives pleaded for leniency for what they said was a bad decision in a difficult moment doing a dangerous job. His lawyers condemned the notion that Raja,Jordan as a Muslim man of Asian descent,Jordan was motivated by racial prejudice.

# React Element 87 2019/06/12 2:08 vbjoczf@hotmaill.com
http://www.jordan12gymred.us/ Jordan 12 Gym Red 2018

# Pandora 2019/06/16 8:53 prpbvbegti@hotmaill.com
http://www.pandora-jewelryoutlet.us/ pandora bracelets

# Cheap Sports Jerseys 2019/06/29 3:40 molkzp@hotmaill.com
http://www.nfljerseyscheapwholesale.us/ NFL Jerseys Cheap

# Nike Air Max 270 2019/07/02 9:21 tbejxpvhsds@hotmaill.com
http://www.nikefactoryoutletstoreonline.us/ nike factory outlet store online

# Adidas Yeezy 2019/07/14 14:40 uqakrmy@hotmaill.com
http://www.yeezy-shoes.in.net/ Yeezy Shoes

# Yeezy 2019/08/07 3:06 dfzqggx@hotmaill.com
http://www.adidasyeezy.de/ Yeezy

# Nike Outlet Online 2019/08/13 12:30 wwkskscs@hotmaill.com
http://www.yeezy-350.org.uk/ Yeezy

# Adidas Yeezy 2019/08/19 9:29 zrfukrbahd@hotmaill.com
http://www.nike--outlet.us/ Nike Outlet

# Yeezy 350 2019/08/25 2:55 bqvmgzr@hotmaill.com
http://www.jordan11-concord.com/ air jordan 11 concord

# Yeezys 2019/09/16 7:53 okncmspel@hotmaill.com
lczekvlbwx,Thanks a lot for providing us with this recipe of Cranberry Brisket. I've been wanting to make this for a long time but I couldn't find the right recipe. Thanks to your help here.

# re: Ruby ??????? 2021/08/08 0:10 hydroxychloroquine sulfate tabs 200mg
cloriquin https://chloroquineorigin.com/# how do i get hydroxychloroquine

# alnafcgldngv 2022/06/01 3:02 kehkoehj
erythromycin iv http://erythromycinn.com/#

Post Feedback

タイトル
名前
Url:
コメント: