1.\" $NetBSD: remainder.3,v 1.2 2011/09/18 05:33:14 jruoho Exp $ 2.\" 3.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen@iki.fi> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25.\" POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd September 18, 2011 28.Dt REMAINDER 3 29.Os 30.Sh NAME 31.Nm remainder , 32.Nm remainderf , 33.Nm remquo , 34.Nm remquof 35.Nd remainder functions 36.Sh LIBRARY 37.Lb libm 38.Sh SYNOPSIS 39.In math.h 40.Ft double 41.Fn remainder "double x" "double y" 42.Ft float 43.Fn remainderf "float x" "float y" 44.Ft double 45.Fn remquo "double x" "double y" "int *quo" 46.Ft float 47.Fn remquof "float x" "float y" "int *quo" 48.Sh DESCRIPTION 49Provided that 50.Fa y 51\*(Ne 0 , 52the 53.Fn remainder 54and 55.Fn remainderf 56functions calculate the floating-point remainder 57.Fa r 58of 59.Bd -ragged -offset indent 60.Va r 61= 62.Va x - ny , 63.Ed 64.Pp 65where 66.Fa n 67is the integral value nearest to the exact value of 68.Fa x 69/ 70.Fa y . 71If 72.Bd -ragged -offset indent 73.Va | n 74- 75.Va x / y | 76= 1/2 , 77.Ed 78.Pp 79the value 80.Fa n 81is chosen to be even. 82Consequently, the remainder is computed exactly and 83.Va | r | 84\*(Le 85.Fa | y | 86/ 2 . 87.Pp 88Also the 89.Fn remquo 90and 91.Fn remquof 92functions calculate the remainder as described above. 93But these additionally use 94.Fa quo 95to store a value whose sign is the sign of 96.Va x / y 97and whose magnitude is congruent modulo 98.Va 2^k 99to the magnitude of the integral quotient of 100.Va x / y , 101where 102.Fa k 103is an implementation-defined integer greater than or equal to 3. 104.Pp 105The rationale of the 106.Fn remquo 107family of functions relates to situations where 108only few bits of the quotient are required. 109The exact representation of the quotient may not be meaningful when 110.Fa x 111is large in magnitude compared to 112.Fa y . 113.Sh RETURN VALUES 114The functions return the remainder independent of the rounding mode. 115If 116.Fa y 117is zero , 118\*(Na 119is returned and a domain error occurs. 120A domain error occurs and a 121\*(Na 122is returned also when 123.Fa x 124is infinite but 125.Fa y 126is not a 127\*(Na. 128If either 129.Fa x 130or 131.Fa y 132is 133\*(Na, 134a 135\*(Na 136is always returned. 137.Sh SEE ALSO 138.Xr div 3 , 139.Xr fast_remainder32 3 , 140.Xr fmod 3 , 141.Xr math 3 142.Sh STANDARDS 143The described functions conform to 144.St -isoC-99 . 145