-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add big-int #198
Add big-int #198
Conversation
src/big-int.satyg
Outdated
val sub : t -> t -> t | ||
val mul : t -> t -> t | ||
val div : t -> t -> t | ||
val mod- : t -> t -> t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Int.satyg の方に mod-
がないのか…… でもこれはあった方がいいと思うので残しときましょう(後で Int の方に mod-
を追加すべき案件)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(これは今回のPRで何かする必要はないです)
src/big-int.satyg
Outdated
val sub : t -> t -> t | ||
val mul : t -> t -> t | ||
val div : t -> t -> t | ||
val mod- : t -> t -> t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(これは今回のPRで何かする必要はないです)
src/big-int.satyg
Outdated
|
||
|
||
% 繰り上がり処理を行う | ||
let carry-and-fix (is-plus, lst) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あーなるほど、これって数を10進表記にした時の各桁の数字をリストとして表してるんですね。
各要素をN bitの符号なし整数として表現した方が、計算速度が上がるのとビット演算が実装しやすくなるのとで好ましいと思います。2^N進数として表記した時の各桁の数字をリストにする感じになるので実装の基本的な方針は代わらないはず。OCamlの整数型は63bitだったはずなのでキャリーとかの計算しやすさを考えるとN=62にするのがよさそう。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ただ今ちゃんと動いてる時点でめちゃくちゃ偉いし、あまり一つのコードレビューを長くしたくないので。一旦このままの実装でmergeしてしまってもいいかなと思います。この実装でビット演算を実装するのはキツいと思うのでビット演算はなしで大丈夫です!
src/big-int.satyg
Outdated
| [] -> str | ||
| i::is -> sub is ((Int.to-string i)^str) | ||
in | ||
let (b, lst) = t in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(あまり重要でない点) b
に is-positive
のような名前をつけてくれるとコードが読みやすくなって嬉しいです。
src/big-int.satyg
Outdated
| x::y::zs -> ( | ||
if Int.(x >= 10) then | ||
let k = x / 10 in | ||
let new-x = x - (10 * k) in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かい点ですがここは x mod 10
と書いた方が簡潔ですね(参考:https://github.com/nyuichi/satysfi-base/blob/master/src/int.satyg#L77)
src/big-int.satyg
Outdated
let (is-ok, new-lst) = | ||
lst | ||
|> sub1 [] | ||
|> sub2 | ||
in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
デッドコードっぽい?
かなり遅くなりましたが、指摘点修正しました |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
マージしちゃってよいと思います、お疲れさまでした 👍
ありがとうございます🙏 |
No description provided.