정의
$sin라디안 단위로 측정된 값의 사인을 반환합니다.
$sin의 구문은 다음과 같습니다:{ $sin: <expression> } $sintakes any valid expression that resolves to a number. If the expression returns a value in degrees, use the$degreesToRadiansoperator to convert the result to radians.$sin기본값double$sin128으로<expression>는 값을 로 반환합니다. 는 128가 비트 십진수 값으로 해석되는 한 값을 비트 십진수로 반환할 수도 있습니다.표현식에 대한 자세한 내용은 표현식을 참조하세요 .
행동
null, NaN 및 +/- Infinity
If the argument resolves to a value of null or refers to a field that is missing, $sin returns null. If the argument resolves to NaN, $sin returns NaN. If the argument resolves to negative or positive infinity, $sin throws an error.
예시 | 결과 | |||
|---|---|---|---|---|
|
| |||
|
| |||
or
| 다음과 같은 형식의 출력과 유사한 오류 메시지를 표시합니다. |
예시
trigonometry 컬렉션에는 빗변과 직각 삼각형의 각 하나를 저장하는 문서가 포함되어 있습니다.
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("53.13010235415597870314438744090659"), "hypotenuse" : Decimal128("5") }
The following aggregation operation uses the $sin expression to calculate the side opposite to angle_a and add it to the input document using the $addFields pipeline stage.
db.trigonometry.aggregate([ { $addFields : { "side_b" : { $multiply : [ { $sin : {$degreesToRadians : "$angle_a"} }, "$hypotenuse" ] } } } ])
$degreesToRadians 표현식은 angle_a의 각도 값을 라디안 단위의 해당 값으로 변환합니다.
이 명령은 다음 출력을 반환합니다.
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("53.13010235415597870314438744090659"), "side_b" : Decimal128("4.000000000000000000000000000000000"), "hypotenuse" : Decimal128("5"), }
angle_a 및 는 hypotenuse 128비트 십진수로 저장되므로 $sin 의 출력은 128비트 십진수입니다.
trigonometry 컬렉션에는 빗변과 직각 삼각형의 각 하나를 저장하는 문서가 포함되어 있습니다.
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("0.9272952180016122324285124629224288"), "hypotenuse" : Decimal128("5") }
The following aggregation operation uses the $sin expression to calculate the side opposite to angle_a and add it to the input document using the $addFields pipeline stage.
db.trigonometry.aggregate([ { $addFields : { "side_b" : { $multiply : [ { $sin : "$angle_a" }, "$hypotenuse" ] } } } ])
이 명령은 다음 출력을 반환합니다.
{ "_id" : ObjectId("5c50782193f833234ba90d85"), "angle_a" : Decimal128("0.9272952180016122324285124629224288"), "side_b" : Decimal128("4.000000000000000000000000000000000"), "hypotenuse" : Decimal128("5"), }
Since angle_a and hypotenuse are stored as 128-bit decimals, the output of $sin is a 128-bit decimal.