No.2ベストアンサー
- 回答日時:
Superficially speaking, it depends on the specification of a programming language.
Technically speaking, as I assume this is what you really want to know, NO.
For instance, right-shifting 9 a bit may be recognized as an integer type, whereas flooring 9 / 2 may be recognized as a float type in most cases.
Does an integer type equal to a float type? They are DIFFERENT; however, generally speaking, we want to treat both integers and floating point numbers as just numbers; therefore a specification of a programming language defines to treat so on calculation for its convenience, or user-friendliness.
On the other hand, for anti-example, there is a stroooooongly typed language like OCaml. This heck does not allow us to do addition/subtraction/multiplication/division between integers and floating point numbers.
# 1 + 2.0;;
Error: This expression has type float but an expression was expected of type
int
Thus, the language like OCaml easily says NO to what you've asked.
# Int.shift_right 9 1 == Float.floor(9.0 /. 2.0);;
Error: This expression has type float but an expression was expected of type
int
Now you know, at the high-level programming language layer, "it depends".
In addition to that, by the way, some modern languages have fraction now. If you love to use them, you would not be annoyed with sickly flooooooating point numbers any more.
;; Racket(A Lisp implementation: https://racket-lang.org)
> (/ 9 2)
4 1/2
> (floor (/ 9 2))
4
>
# Python
>>> from fractions import Fraction
>>> from math import floor
>>> Fraction(9, 2)
Fraction(9, 2)
>>> floor(Fraction(9, 2))
4
※: You may know what "type" is, but here let it be cleared more.
A Type is basically a TAG to encode/decode something in binary level.
Everything we want to "express" is encoded into binaries and put in memories, with a certain rule. Everything in memories is decoded into what we are familiar to on the monitor.
Now, how to put "what we want to express" as binaries, or data, heavily relies on "rules", with clues to know "what is what". In order to do this, there are types; in other words, there are different rules to put binaries for integers and floating point numbers.
You had better read this:
IEEE 754:
https://en.wikipedia.org/wiki/IEEE_754
To put "floating point numbers" in memories is much more complex than to do integers. Headache. Give me a break.
Anyway, at the very lowest level, we cannot say integers, even though it is made by right shift, are equal to floating point numbers.
ありがとうございます〜
i just skimmed through the page but I'm still trying to wrap my head around this. I mean why do they have so much variance in just processing numbers?? Can't we unify all this, mess ?? please??
思ってたよりもっと難しい世界がみえちゃいました(´;ω;`)
No.4
- 回答日時:
「あまりがあるならあまり引いて割り切れる状態で」で言いたい意味しだいかなあ...
(N-1)/2 {ただし切り捨て} と
N/2 {ただし切り捨て} が同じなわけはないです。
N が整数であることを前提に、
(N が偶数なら N 奇数なら N-1)/2 と言っているのなら、
N/2 {ただし切り捨て} と同じ値になります。
No.1
- 回答日時:
○ // とは何か?
/ が割り算なのはほぼ確実だとして(それでも小数点以下の処理が言語や状況によって違う)
// は言語によって扱いが違う: C言語に近い文法を使うものでは、 // は行末までのコメントになる。
○ Pythonだとして、これくらいのことなら人に聞く前に自分で実際に色々試してみればいい
切捨: math.floor
https://docs.python.org/ja/3.12/library/math.htm …
import math
N=4 #いろいろ変えてみる
print( (N-1) // 2, N / 2, math.floor(N / 2) )
○ そもそも「1ひく」ことと「あまりがあるならあまり引いて割り切れる状態にする」ことは同じではない。
○ついでに「右ビットシフト」と「2で割る」のは同じではない。
(浮動小数点数等)
ごめんなさい。パイソンでかんがえてました。そですよね。右ビットシフトでずれたら各桁のオーダーが一つ減って半分になるとおもいました。
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
似たような質問が見つかりました
- 情報処理技術者・Microsoft認定資格 2進数の問題を教えてください。 1 2022/07/27 09:42
- 数学 以下の問題が分かりません。 8ビット浮動小数点数が、最上位ビットから順に符号1ビット、指数部3ビット 4 2023/07/22 16:06
- 数学 量子コンピュータ内で扱う量子ビットは離散値ですか? 2 2023/09/06 11:33
- 情報処理技術者・Microsoft認定資格 情報技術の問題についてです。 10進数の−36を以下のような16ビットの浮動小数点表示にするといくつ 3 2022/05/21 19:53
- Excel(エクセル) エクセルのオートフィル?ドラッグして連続ででる値が壊れている。これはなに? 2 2023/12/21 11:13
- 数学 確率の問題 4 2023/02/24 01:07
- 教育学 エクセルで小数点以下を四捨五入について教えてください。 2 2023/04/05 17:33
- 統計学 教えてください! あるくじ引きには5枚に1枚の割合でアタリが入っていると宣伝しているが、実際には20 7 2023/05/29 09:10
- Java Java モンスターブリーダー 1 2023/02/05 09:44
- 数学 多様体について質問です。 Rを実数全体としてf:S^n={(p_1,…,p_(n+1)∈R^(n+1 2 2023/06/24 00:54
このQ&Aを見た人はこんなQ&Aも見ています
-
風水の観点で選ぶ観葉植物とは?置き場所や上げたい運気ごとの注意点を紹介!
観葉植物で運気をアップするコツを、風水デザイン1級建築士の福島昌彦さんに伺った。
-
プログラミングについて。 1つのループで Aという計算と Bという計算をするのと これらを分けて2つ
C言語・C++・C#
-
mallocについて
C言語・C++・C#
-
C言語をコンパイルするとコンピュータ上でどう動くかというコードになるみたいな説明をよく聞くのですがこ
C言語・C++・C#
-
-
4
C言語って古いですか?
C言語・C++・C#
-
5
これなにがちがうんですか??
C言語・C++・C#
-
6
double型が正常に認識されていない恐れ
C言語・C++・C#
-
7
C言語 配列と関数の練習問題
C言語・C++・C#
-
8
Linux Cプログラミングを学ぶための書籍
C言語・C++・C#
-
9
どちのほうがすきですか?
C言語・C++・C#
-
10
gccを行ってもexeファイルが生成されない
C言語・C++・C#
-
11
こんなことてしますか??
C言語・C++・C#
-
12
Stuck
C言語・C++・C#
-
13
インクリメント演算子のみを用いて、下に表示されるようにプログラムします 99 100 102 103
C言語・C++・C#
-
14
C言語関数違いについて。
C言語・C++・C#
-
15
プログラミング言語の制作方法について
C言語・C++・C#
-
16
C言語 列挙型(enum型)変数について
C言語・C++・C#
-
17
システムエンジニアの適正について
C言語・C++・C#
-
18
WindowsのCapsLock(キャップスロック)って、何の意味があるんですか?
C言語・C++・C#
-
19
なんかC言語でプログラム書いてると脳汁というかエクスタシーというかなんかすげえ気持ちいいんですけどな
C言語・C++・C#
-
20
C言語について。
C言語・C++・C#
関連するカテゴリからQ&Aを探す
おすすめ情報
このQ&Aを見た人がよく見るQ&A
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
5%割引の際の、小数点以下の扱...
-
COBOLの計算方法
-
今投稿して解決したのですが 更...
-
負の数の四捨五入の方法
-
数字の double 型 を int型...
-
MATLABで小数を整数にするには?
-
雇用保険料の計算式について(E...
-
右ビットシフト
-
ネットビジネスのエクセルの切...
-
端数処理における「小数以下」...
-
小数点第2位の切捨て(エクセル...
-
次の計算式を使って、 利益率12...
-
Access 1000以下を切り捨てる関数
-
「未満と以上」使う範囲。
-
Excel有効数字の丸め方「0捨1入」
-
C言語
-
四捨五入について
-
なぜ消費税10%は×1.1なのですか...
-
法人税・消費税修正申告納付の仕訳
-
明らかに、消費税は、法人税の...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
5%割引の際の、小数点以下の扱...
-
Access 1000以下を切り捨てる関数
-
今投稿して解決したのですが 更...
-
COBOLの計算方法
-
Excel有効数字の丸め方「0捨1入」
-
駐車場賃料の日割り計算について
-
数字の double 型 を int型...
-
負の数の四捨五入の方法
-
数字の下二桁を削除したい
-
エクセルでの小数点以下切り捨...
-
50銭以下切り捨て51銭以上切...
-
ACCESSの切り上げ
-
「未満と以上」使う範囲。
-
勤務の稼働時間の計算がわかり...
-
次の計算式を使って、 利益率12...
-
ADOで算術型のRound関数を使いたい
-
ツェラーの公式について
-
小数点第2位の切捨て(エクセル...
-
excel関数で四捨五入以外の切り...
-
PHPで計算問題
おすすめ情報