id int32 0 167k | repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens listlengths 21 1.41k | docstring stringlengths 6 2.61k | docstring_tokens listlengths 3 215 | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5,300 | juju/juju | container/lxd/manager.go | ListContainers | func (m *containerManager) ListContainers() ([]instances.Instance, error) {
containers, err := m.server.FilterContainers(m.namespace.Prefix())
if err != nil {
return nil, errors.Trace(err)
}
var result []instances.Instance
for _, i := range containers {
result = append(result, &lxdInstance{i.Name, m.server.ContainerServer})
}
return result, nil
} | go | func (m *containerManager) ListContainers() ([]instances.Instance, error) {
containers, err := m.server.FilterContainers(m.namespace.Prefix())
if err != nil {
return nil, errors.Trace(err)
}
var result []instances.Instance
for _, i := range containers {
result = append(result, &lxdInstance{i.Name, m.server.ContainerServer})
}
return result, nil
} | [
"func",
"(",
"m",
"*",
"containerManager",
")",
"ListContainers",
"(",
")",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"error",
")",
"{",
"containers",
",",
"err",
":=",
"m",
".",
"server",
".",
"FilterContainers",
"(",
"m",
".",
"namespace",
".... | // ListContainers implements container.Manager. | [
"ListContainers",
"implements",
"container",
".",
"Manager",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/manager.go#L127-L138 |
5,301 | juju/juju | container/lxd/manager.go | getContainerSpec | func (m *containerManager) getContainerSpec(
instanceConfig *instancecfg.InstanceConfig,
cons constraints.Value,
series string,
networkConfig *container.NetworkConfig,
storageConfig *container.StorageConfig,
callback environs.StatusCallbackFunc,
) (ContainerSpec, error) {
imageSources, err := m.getImageSources()
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
// Lock around finding an image.
// The provisioner works concurrently to create containers.
// If an image needs to be copied from a remote, we don't want many
// goroutines attempting to do it at once.
m.imageMutex.Lock()
found, err := m.server.FindImage(series, jujuarch.HostArch(), imageSources, true, callback)
m.imageMutex.Unlock()
if err != nil {
return ContainerSpec{}, errors.Annotatef(err, "acquiring LXD image")
}
name, err := m.namespace.Hostname(instanceConfig.MachineId)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
nics, unknown, err := m.networkDevicesFromConfig(networkConfig)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
logger.Debugf("configuring container %q with network devices: %v", name, nics)
// If the default LXD bridge was supplied in network config,
// but without a CIDR, attempt to ensure it is configured for IPv4.
// If there are others with incomplete info, log a warning.
if len(unknown) > 0 {
if len(unknown) == 1 && unknown[0] == network.DefaultLXDBridge && m.server.networkAPISupport {
mod, err := m.server.EnsureIPv4(network.DefaultLXDBridge)
if err != nil {
return ContainerSpec{}, errors.Annotate(err, "ensuring default bridge IPv4 config")
}
if mod {
logger.Infof(`added "auto" IPv4 configuration to default LXD bridge`)
}
} else {
logger.Warningf("no CIDR was detected for the following networks: %v", unknown)
}
}
// If there was no incoming interface info, then at this point we know
// that nics were generated by falling back to either a single "eth0",
// or devices from the profile.
// Ensure that the devices are represented in the cloud-init user-data.
if len(networkConfig.Interfaces) == 0 {
interfaces, err := InterfaceInfoFromDevices(nics)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
networkConfig.Interfaces = interfaces
}
// CloudInitUserData creates our own ENI/netplan.
// We need to disable cloud-init networking to make it work.
userData, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
cfg := map[string]string{
UserDataKey: string(userData),
NetworkConfigKey: cloudinit.CloudInitNetworkConfigDisabled,
AutoStartKey: "true",
// Extra info to indicate the origin of this container.
JujuModelKey: m.modelUUID,
}
spec := ContainerSpec{
Name: name,
Image: found,
Config: cfg,
Profiles: instanceConfig.Profiles,
Devices: nics,
}
spec.ApplyConstraints(m.server.serverVersion, cons)
return spec, nil
} | go | func (m *containerManager) getContainerSpec(
instanceConfig *instancecfg.InstanceConfig,
cons constraints.Value,
series string,
networkConfig *container.NetworkConfig,
storageConfig *container.StorageConfig,
callback environs.StatusCallbackFunc,
) (ContainerSpec, error) {
imageSources, err := m.getImageSources()
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
// Lock around finding an image.
// The provisioner works concurrently to create containers.
// If an image needs to be copied from a remote, we don't want many
// goroutines attempting to do it at once.
m.imageMutex.Lock()
found, err := m.server.FindImage(series, jujuarch.HostArch(), imageSources, true, callback)
m.imageMutex.Unlock()
if err != nil {
return ContainerSpec{}, errors.Annotatef(err, "acquiring LXD image")
}
name, err := m.namespace.Hostname(instanceConfig.MachineId)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
nics, unknown, err := m.networkDevicesFromConfig(networkConfig)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
logger.Debugf("configuring container %q with network devices: %v", name, nics)
// If the default LXD bridge was supplied in network config,
// but without a CIDR, attempt to ensure it is configured for IPv4.
// If there are others with incomplete info, log a warning.
if len(unknown) > 0 {
if len(unknown) == 1 && unknown[0] == network.DefaultLXDBridge && m.server.networkAPISupport {
mod, err := m.server.EnsureIPv4(network.DefaultLXDBridge)
if err != nil {
return ContainerSpec{}, errors.Annotate(err, "ensuring default bridge IPv4 config")
}
if mod {
logger.Infof(`added "auto" IPv4 configuration to default LXD bridge`)
}
} else {
logger.Warningf("no CIDR was detected for the following networks: %v", unknown)
}
}
// If there was no incoming interface info, then at this point we know
// that nics were generated by falling back to either a single "eth0",
// or devices from the profile.
// Ensure that the devices are represented in the cloud-init user-data.
if len(networkConfig.Interfaces) == 0 {
interfaces, err := InterfaceInfoFromDevices(nics)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
networkConfig.Interfaces = interfaces
}
// CloudInitUserData creates our own ENI/netplan.
// We need to disable cloud-init networking to make it work.
userData, err := containerinit.CloudInitUserData(instanceConfig, networkConfig)
if err != nil {
return ContainerSpec{}, errors.Trace(err)
}
cfg := map[string]string{
UserDataKey: string(userData),
NetworkConfigKey: cloudinit.CloudInitNetworkConfigDisabled,
AutoStartKey: "true",
// Extra info to indicate the origin of this container.
JujuModelKey: m.modelUUID,
}
spec := ContainerSpec{
Name: name,
Image: found,
Config: cfg,
Profiles: instanceConfig.Profiles,
Devices: nics,
}
spec.ApplyConstraints(m.server.serverVersion, cons)
return spec, nil
} | [
"func",
"(",
"m",
"*",
"containerManager",
")",
"getContainerSpec",
"(",
"instanceConfig",
"*",
"instancecfg",
".",
"InstanceConfig",
",",
"cons",
"constraints",
".",
"Value",
",",
"series",
"string",
",",
"networkConfig",
"*",
"container",
".",
"NetworkConfig",
... | // getContainerSpec generates a spec for creating a new container.
// It sources an image based on the input series, and transforms the input
// config objects into LXD configuration, including cloud init user data. | [
"getContainerSpec",
"generates",
"a",
"spec",
"for",
"creating",
"a",
"new",
"container",
".",
"It",
"sources",
"an",
"image",
"based",
"on",
"the",
"input",
"series",
"and",
"transforms",
"the",
"input",
"config",
"objects",
"into",
"LXD",
"configuration",
"i... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/manager.go#L148-L238 |
5,302 | juju/juju | container/lxd/manager.go | getImageSources | func (m *containerManager) getImageSources() ([]ServerSpec, error) {
imURL := m.imageMetadataURL
// Unless the configuration explicitly requests the daily stream,
// an empty image metadata URL results in a search of the default sources.
if imURL == "" && m.imageStream != "daily" {
logger.Debugf("checking default image metadata sources")
return []ServerSpec{CloudImagesRemote, CloudImagesDailyRemote}, nil
}
// Otherwise only check the daily stream.
if imURL == "" {
return []ServerSpec{CloudImagesDailyRemote}, nil
}
imURL, err := imagemetadata.ImageMetadataURL(imURL, m.imageStream)
if err != nil {
return nil, errors.Annotatef(err, "generating image metadata source")
}
imURL = EnsureHTTPS(imURL)
remote := ServerSpec{
Name: strings.Replace(imURL, "https://", "", 1),
Host: imURL,
Protocol: SimpleStreamsProtocol,
}
// If the daily stream was configured with custom image metadata URL,
// only use the Ubuntu daily as a fallback.
if m.imageStream == "daily" {
return []ServerSpec{remote, CloudImagesDailyRemote}, nil
}
return []ServerSpec{remote, CloudImagesRemote, CloudImagesDailyRemote}, nil
} | go | func (m *containerManager) getImageSources() ([]ServerSpec, error) {
imURL := m.imageMetadataURL
// Unless the configuration explicitly requests the daily stream,
// an empty image metadata URL results in a search of the default sources.
if imURL == "" && m.imageStream != "daily" {
logger.Debugf("checking default image metadata sources")
return []ServerSpec{CloudImagesRemote, CloudImagesDailyRemote}, nil
}
// Otherwise only check the daily stream.
if imURL == "" {
return []ServerSpec{CloudImagesDailyRemote}, nil
}
imURL, err := imagemetadata.ImageMetadataURL(imURL, m.imageStream)
if err != nil {
return nil, errors.Annotatef(err, "generating image metadata source")
}
imURL = EnsureHTTPS(imURL)
remote := ServerSpec{
Name: strings.Replace(imURL, "https://", "", 1),
Host: imURL,
Protocol: SimpleStreamsProtocol,
}
// If the daily stream was configured with custom image metadata URL,
// only use the Ubuntu daily as a fallback.
if m.imageStream == "daily" {
return []ServerSpec{remote, CloudImagesDailyRemote}, nil
}
return []ServerSpec{remote, CloudImagesRemote, CloudImagesDailyRemote}, nil
} | [
"func",
"(",
"m",
"*",
"containerManager",
")",
"getImageSources",
"(",
")",
"(",
"[",
"]",
"ServerSpec",
",",
"error",
")",
"{",
"imURL",
":=",
"m",
".",
"imageMetadataURL",
"\n\n",
"// Unless the configuration explicitly requests the daily stream,",
"// an empty ima... | // getImageSources returns a list of LXD remote image sources based on the
// configuration that was passed into the container manager. | [
"getImageSources",
"returns",
"a",
"list",
"of",
"LXD",
"remote",
"image",
"sources",
"based",
"on",
"the",
"configuration",
"that",
"was",
"passed",
"into",
"the",
"container",
"manager",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/manager.go#L242-L273 |
5,303 | juju/juju | container/lxd/manager.go | networkDevicesFromConfig | func (m *containerManager) networkDevicesFromConfig(netConfig *container.NetworkConfig) (map[string]device, []string, error) {
if len(netConfig.Interfaces) > 0 {
return DevicesFromInterfaceInfo(netConfig.Interfaces)
} else if netConfig.Device != "" {
return map[string]device{
"eth0": newNICDevice("eth0", netConfig.Device, network.GenerateVirtualMACAddress(), netConfig.MTU),
}, nil, nil
}
nics, err := m.server.GetNICsFromProfile(lxdDefaultProfileName)
return nics, nil, errors.Trace(err)
} | go | func (m *containerManager) networkDevicesFromConfig(netConfig *container.NetworkConfig) (map[string]device, []string, error) {
if len(netConfig.Interfaces) > 0 {
return DevicesFromInterfaceInfo(netConfig.Interfaces)
} else if netConfig.Device != "" {
return map[string]device{
"eth0": newNICDevice("eth0", netConfig.Device, network.GenerateVirtualMACAddress(), netConfig.MTU),
}, nil, nil
}
nics, err := m.server.GetNICsFromProfile(lxdDefaultProfileName)
return nics, nil, errors.Trace(err)
} | [
"func",
"(",
"m",
"*",
"containerManager",
")",
"networkDevicesFromConfig",
"(",
"netConfig",
"*",
"container",
".",
"NetworkConfig",
")",
"(",
"map",
"[",
"string",
"]",
"device",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"netCo... | // networkDevicesFromConfig uses the input container network configuration to
// create a map of network device configuration in the LXD format.
// If there are no interfaces in the input config, but there is a bridge device
// name, return a single "eth0" device with the bridge as its parent.
// The last fall-back is to return the NIC devices from the default profile.
// Names for any networks without a known CIDR are returned in a slice. | [
"networkDevicesFromConfig",
"uses",
"the",
"input",
"container",
"network",
"configuration",
"to",
"create",
"a",
"map",
"of",
"network",
"device",
"configuration",
"in",
"the",
"LXD",
"format",
".",
"If",
"there",
"are",
"no",
"interfaces",
"in",
"the",
"input"... | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/manager.go#L281-L292 |
5,304 | juju/juju | container/lxd/manager.go | LXDProfileNames | func (m *containerManager) LXDProfileNames(containerName string) ([]string, error) {
return m.server.GetContainerProfiles(containerName)
} | go | func (m *containerManager) LXDProfileNames(containerName string) ([]string, error) {
return m.server.GetContainerProfiles(containerName)
} | [
"func",
"(",
"m",
"*",
"containerManager",
")",
"LXDProfileNames",
"(",
"containerName",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"m",
".",
"server",
".",
"GetContainerProfiles",
"(",
"containerName",
")",
"\n",
"}"
] | // LXDProfileNames implements container.LXDProfileManager | [
"LXDProfileNames",
"implements",
"container",
".",
"LXDProfileManager"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/lxd/manager.go#L322-L324 |
5,305 | codegangsta/inject | inject.go | Map | func (i *injector) Map(val interface{}) TypeMapper {
i.values[reflect.TypeOf(val)] = reflect.ValueOf(val)
return i
} | go | func (i *injector) Map(val interface{}) TypeMapper {
i.values[reflect.TypeOf(val)] = reflect.ValueOf(val)
return i
} | [
"func",
"(",
"i",
"*",
"injector",
")",
"Map",
"(",
"val",
"interface",
"{",
"}",
")",
"TypeMapper",
"{",
"i",
".",
"values",
"[",
"reflect",
".",
"TypeOf",
"(",
"val",
")",
"]",
"=",
"reflect",
".",
"ValueOf",
"(",
"val",
")",
"\n",
"return",
"i... | // Maps the concrete value of val to its dynamic type using reflect.TypeOf,
// It returns the TypeMapper registered in. | [
"Maps",
"the",
"concrete",
"value",
"of",
"val",
"to",
"its",
"dynamic",
"type",
"using",
"reflect",
".",
"TypeOf",
"It",
"returns",
"the",
"TypeMapper",
"registered",
"in",
"."
] | 33e0aa1cb7c019ccc3fbe049a8262a6403d30504 | https://github.com/codegangsta/inject/blob/33e0aa1cb7c019ccc3fbe049a8262a6403d30504/inject.go#L141-L144 |
5,306 | codegangsta/inject | inject.go | Set | func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper {
i.values[typ] = val
return i
} | go | func (i *injector) Set(typ reflect.Type, val reflect.Value) TypeMapper {
i.values[typ] = val
return i
} | [
"func",
"(",
"i",
"*",
"injector",
")",
"Set",
"(",
"typ",
"reflect",
".",
"Type",
",",
"val",
"reflect",
".",
"Value",
")",
"TypeMapper",
"{",
"i",
".",
"values",
"[",
"typ",
"]",
"=",
"val",
"\n",
"return",
"i",
"\n",
"}"
] | // Maps the given reflect.Type to the given reflect.Value and returns
// the Typemapper the mapping has been registered in. | [
"Maps",
"the",
"given",
"reflect",
".",
"Type",
"to",
"the",
"given",
"reflect",
".",
"Value",
"and",
"returns",
"the",
"Typemapper",
"the",
"mapping",
"has",
"been",
"registered",
"in",
"."
] | 33e0aa1cb7c019ccc3fbe049a8262a6403d30504 | https://github.com/codegangsta/inject/blob/33e0aa1cb7c019ccc3fbe049a8262a6403d30504/inject.go#L153-L156 |
5,307 | gogap/logrus_mate | hooks/sls/sls.go | Levels | func (p *SLSHook) Levels() []logrus.Level {
if p.AcceptedLevels == nil {
return allLevels
}
return p.AcceptedLevels
} | go | func (p *SLSHook) Levels() []logrus.Level {
if p.AcceptedLevels == nil {
return allLevels
}
return p.AcceptedLevels
} | [
"func",
"(",
"p",
"*",
"SLSHook",
")",
"Levels",
"(",
")",
"[",
"]",
"logrus",
".",
"Level",
"{",
"if",
"p",
".",
"AcceptedLevels",
"==",
"nil",
"{",
"return",
"allLevels",
"\n",
"}",
"\n",
"return",
"p",
".",
"AcceptedLevels",
"\n",
"}"
] | // Levels sets which levels to sent to sls | [
"Levels",
"sets",
"which",
"levels",
"to",
"sent",
"to",
"sls"
] | ceff7932618ef5a9990d46b7fcd43baaaeaf6e50 | https://github.com/gogap/logrus_mate/blob/ceff7932618ef5a9990d46b7fcd43baaaeaf6e50/hooks/sls/sls.go#L115-L120 |
5,308 | gogap/logrus_mate | hooks/file/file.go | newFileWriter | func newFileWriter() *fileLogWriter {
w := &fileLogWriter{
Daily: true,
MaxDays: 7,
Rotate: true,
RotatePerm: "0440",
Level: LevelDebug,
Perm: "0660",
}
return w
} | go | func newFileWriter() *fileLogWriter {
w := &fileLogWriter{
Daily: true,
MaxDays: 7,
Rotate: true,
RotatePerm: "0440",
Level: LevelDebug,
Perm: "0660",
}
return w
} | [
"func",
"newFileWriter",
"(",
")",
"*",
"fileLogWriter",
"{",
"w",
":=",
"&",
"fileLogWriter",
"{",
"Daily",
":",
"true",
",",
"MaxDays",
":",
"7",
",",
"Rotate",
":",
"true",
",",
"RotatePerm",
":",
"\"",
"\"",
",",
"Level",
":",
"LevelDebug",
",",
... | // newFileWriter create a FileLogWriter returning as LoggerInterface. | [
"newFileWriter",
"create",
"a",
"FileLogWriter",
"returning",
"as",
"LoggerInterface",
"."
] | ceff7932618ef5a9990d46b7fcd43baaaeaf6e50 | https://github.com/gogap/logrus_mate/blob/ceff7932618ef5a9990d46b7fcd43baaaeaf6e50/hooks/file/file.go#L77-L87 |
5,309 | gogap/logrus_mate | hooks/file/file.go | WriteMsg | func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
if level > w.Level {
return nil
}
h, d := formatTimeHeader(when)
msg = string(h) + msg + "\n"
if w.Rotate {
w.RLock()
if w.needRotate(len(msg), d) {
w.RUnlock()
w.Lock()
if w.needRotate(len(msg), d) {
if err := w.doRotate(when); err != nil {
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
}
}
w.Unlock()
} else {
w.RUnlock()
}
}
w.Lock()
_, err := w.fileWriter.Write([]byte(msg))
if err == nil {
w.maxLinesCurLines++
w.maxSizeCurSize += len(msg)
}
w.Unlock()
return err
} | go | func (w *fileLogWriter) WriteMsg(when time.Time, msg string, level int) error {
if level > w.Level {
return nil
}
h, d := formatTimeHeader(when)
msg = string(h) + msg + "\n"
if w.Rotate {
w.RLock()
if w.needRotate(len(msg), d) {
w.RUnlock()
w.Lock()
if w.needRotate(len(msg), d) {
if err := w.doRotate(when); err != nil {
fmt.Fprintf(os.Stderr, "FileLogWriter(%q): %s\n", w.Filename, err)
}
}
w.Unlock()
} else {
w.RUnlock()
}
}
w.Lock()
_, err := w.fileWriter.Write([]byte(msg))
if err == nil {
w.maxLinesCurLines++
w.maxSizeCurSize += len(msg)
}
w.Unlock()
return err
} | [
"func",
"(",
"w",
"*",
"fileLogWriter",
")",
"WriteMsg",
"(",
"when",
"time",
".",
"Time",
",",
"msg",
"string",
",",
"level",
"int",
")",
"error",
"{",
"if",
"level",
">",
"w",
".",
"Level",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"h",
",",
"d",
... | // WriteMsg write logger message into file. | [
"WriteMsg",
"write",
"logger",
"message",
"into",
"file",
"."
] | ceff7932618ef5a9990d46b7fcd43baaaeaf6e50 | https://github.com/gogap/logrus_mate/blob/ceff7932618ef5a9990d46b7fcd43baaaeaf6e50/hooks/file/file.go#L138-L168 |
5,310 | ericlagergren/decimal | math/log.go | Log10 | func Log10(z, x *decimal.Big) *decimal.Big {
if logSpecials(z, x) {
return z
}
// If x is a power of 10 the result is the exponent and exact.
var tpow bool
if m, u := decimal.Raw(x); *m != c.Inflated {
tpow = arith.PowOfTen(*m)
} else {
tpow = arith.PowOfTenBig(u)
}
if tpow {
ctx := decimal.Context{Precision: precision(z)}
return ctx.Set(z, z.SetMantScale(int64(adjusted(x)), 0))
}
return log(z, x, true)
} | go | func Log10(z, x *decimal.Big) *decimal.Big {
if logSpecials(z, x) {
return z
}
// If x is a power of 10 the result is the exponent and exact.
var tpow bool
if m, u := decimal.Raw(x); *m != c.Inflated {
tpow = arith.PowOfTen(*m)
} else {
tpow = arith.PowOfTenBig(u)
}
if tpow {
ctx := decimal.Context{Precision: precision(z)}
return ctx.Set(z, z.SetMantScale(int64(adjusted(x)), 0))
}
return log(z, x, true)
} | [
"func",
"Log10",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"logSpecials",
"(",
"z",
",",
"x",
")",
"{",
"return",
"z",
"\n",
"}",
"\n\n",
"// If x is a power of 10 the result is the exponent and exact.",
"v... | // Log10 sets z to the common logarithm of x and returns z. | [
"Log10",
"sets",
"z",
"to",
"the",
"common",
"logarithm",
"of",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/log.go#L10-L27 |
5,311 | ericlagergren/decimal | math/log.go | Log | func Log(z, x *decimal.Big) *decimal.Big {
if logSpecials(z, x) {
return z
}
if x.IsInt() {
if v, ok := x.Uint64(); ok {
switch v {
case 1:
// ln 1 = 0
return z.SetMantScale(0, 0)
case 10:
// Specialized function.
return ln10(z, precision(z))
}
}
}
return log(z, x, false)
} | go | func Log(z, x *decimal.Big) *decimal.Big {
if logSpecials(z, x) {
return z
}
if x.IsInt() {
if v, ok := x.Uint64(); ok {
switch v {
case 1:
// ln 1 = 0
return z.SetMantScale(0, 0)
case 10:
// Specialized function.
return ln10(z, precision(z))
}
}
}
return log(z, x, false)
} | [
"func",
"Log",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"logSpecials",
"(",
"z",
",",
"x",
")",
"{",
"return",
"z",
"\n",
"}",
"\n",
"if",
"x",
".",
"IsInt",
"(",
")",
"{",
"if",
"v",
",",
... | // Log sets z to the natural logarithm of x and returns z. | [
"Log",
"sets",
"z",
"to",
"the",
"natural",
"logarithm",
"of",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/log.go#L30-L47 |
5,312 | ericlagergren/decimal | sql/postgres/decimal.go | Value | func (d *Decimal) Value() (driver.Value, error) {
if d.V == nil {
if d.Zero {
return "0", nil
}
return nil, nil
}
v := d.V
if v.IsNaN(0) {
return "NaN", nil
}
if v.IsInf(0) {
return nil, errors.New("Decimal.Value: DECIMAL does not accept Infinities")
}
dl := v.Precision() // length of d
sl := int(v.Scale()) // length of fractional part
if il := dl - sl; il > MaxIntegralDigits {
if !d.Round {
return nil, &LengthError{Part: "integral", N: il, max: MaxIntegralDigits}
}
// Rounding down the integral part automatically chops off the fractional
// part.
return v.Round(MaxIntegralDigits).String(), nil
}
if sl > MaxFractionalDigits {
if !d.Round {
return nil, &LengthError{Part: "fractional", N: sl, max: MaxFractionalDigits}
}
v.Round(dl - (sl - MaxFractionalDigits))
}
return v.String(), nil
} | go | func (d *Decimal) Value() (driver.Value, error) {
if d.V == nil {
if d.Zero {
return "0", nil
}
return nil, nil
}
v := d.V
if v.IsNaN(0) {
return "NaN", nil
}
if v.IsInf(0) {
return nil, errors.New("Decimal.Value: DECIMAL does not accept Infinities")
}
dl := v.Precision() // length of d
sl := int(v.Scale()) // length of fractional part
if il := dl - sl; il > MaxIntegralDigits {
if !d.Round {
return nil, &LengthError{Part: "integral", N: il, max: MaxIntegralDigits}
}
// Rounding down the integral part automatically chops off the fractional
// part.
return v.Round(MaxIntegralDigits).String(), nil
}
if sl > MaxFractionalDigits {
if !d.Round {
return nil, &LengthError{Part: "fractional", N: sl, max: MaxFractionalDigits}
}
v.Round(dl - (sl - MaxFractionalDigits))
}
return v.String(), nil
} | [
"func",
"(",
"d",
"*",
"Decimal",
")",
"Value",
"(",
")",
"(",
"driver",
".",
"Value",
",",
"error",
")",
"{",
"if",
"d",
".",
"V",
"==",
"nil",
"{",
"if",
"d",
".",
"Zero",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"return",
... | // Value implements driver.Valuer. | [
"Value",
"implements",
"driver",
".",
"Valuer",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/sql/postgres/decimal.go#L41-L74 |
5,313 | ericlagergren/decimal | internal/arith/intlen.go | Length | func Length(x uint64) int {
if x < 10 {
return 1
}
// From https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
r := int((bits.Len64(x) * 1233) >> 12)
if p, _ := Pow10(uint64(r)); x < p {
return r
}
return r + 1
} | go | func Length(x uint64) int {
if x < 10 {
return 1
}
// From https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
r := int((bits.Len64(x) * 1233) >> 12)
if p, _ := Pow10(uint64(r)); x < p {
return r
}
return r + 1
} | [
"func",
"Length",
"(",
"x",
"uint64",
")",
"int",
"{",
"if",
"x",
"<",
"10",
"{",
"return",
"1",
"\n",
"}",
"\n",
"// From https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10",
"r",
":=",
"int",
"(",
"(",
"bits",
".",
"Len64",
"(",
"x",
")",
... | // Length returns the number of digits in x. | [
"Length",
"returns",
"the",
"number",
"of",
"digits",
"in",
"x",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/intlen.go#L9-L19 |
5,314 | ericlagergren/decimal | internal/arith/intlen.go | BigLength | func BigLength(x *big.Int) int {
if x.Sign() == 0 {
return 1
}
var (
m uint64
nb = uint64(x.BitLen())
)
// overflowCutoff is the largest number where N * 0x268826A1 <= 1<<63 - 1
const overflowCutoff = 14267572532
if nb > overflowCutoff {
// Given the identity ``log_n a + log_n b = log_n a*b''
// and ``(1<<63 - 1) / overflowCutoff < overFlowCutoff''
// we can break nb into two factors: overflowCutoff and X.
// overflowCutoff / log10(2)
m = 1<<32 - 1
nb = (nb / overflowCutoff) + (nb % overflowCutoff)
}
// 0x268826A1/2^31 is an approximation of log10(2). See ilog10.
// The more accurate approximation 0x268826A13EF3FE08/2^63 overflows.
m += ((nb + 1) * 0x268826A1) >> 31
if x.CmpAbs(BigPow10(m)) < 0 {
return int(m)
}
return int(m + 1)
} | go | func BigLength(x *big.Int) int {
if x.Sign() == 0 {
return 1
}
var (
m uint64
nb = uint64(x.BitLen())
)
// overflowCutoff is the largest number where N * 0x268826A1 <= 1<<63 - 1
const overflowCutoff = 14267572532
if nb > overflowCutoff {
// Given the identity ``log_n a + log_n b = log_n a*b''
// and ``(1<<63 - 1) / overflowCutoff < overFlowCutoff''
// we can break nb into two factors: overflowCutoff and X.
// overflowCutoff / log10(2)
m = 1<<32 - 1
nb = (nb / overflowCutoff) + (nb % overflowCutoff)
}
// 0x268826A1/2^31 is an approximation of log10(2). See ilog10.
// The more accurate approximation 0x268826A13EF3FE08/2^63 overflows.
m += ((nb + 1) * 0x268826A1) >> 31
if x.CmpAbs(BigPow10(m)) < 0 {
return int(m)
}
return int(m + 1)
} | [
"func",
"BigLength",
"(",
"x",
"*",
"big",
".",
"Int",
")",
"int",
"{",
"if",
"x",
".",
"Sign",
"(",
")",
"==",
"0",
"{",
"return",
"1",
"\n",
"}",
"\n\n",
"var",
"(",
"m",
"uint64",
"\n",
"nb",
"=",
"uint64",
"(",
"x",
".",
"BitLen",
"(",
... | // BigLength returns the number of digits in x. | [
"BigLength",
"returns",
"the",
"number",
"of",
"digits",
"in",
"x",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/intlen.go#L22-L52 |
5,315 | ericlagergren/decimal | internal/arith/abs.go | Abs | func Abs(x int64) uint64 {
m := x >> 63
return uint64((x ^ m) - m)
} | go | func Abs(x int64) uint64 {
m := x >> 63
return uint64((x ^ m) - m)
} | [
"func",
"Abs",
"(",
"x",
"int64",
")",
"uint64",
"{",
"m",
":=",
"x",
">>",
"63",
"\n",
"return",
"uint64",
"(",
"(",
"x",
"^",
"m",
")",
"-",
"m",
")",
"\n",
"}"
] | // Abs returns the absolute value of x. | [
"Abs",
"returns",
"the",
"absolute",
"value",
"of",
"x",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/abs.go#L6-L9 |
5,316 | ericlagergren/decimal | internal/arith/abs.go | CmpBits | func CmpBits(x, y []big.Word) (r int) {
// Copied from math/big.nat.go
m := len(x)
n := len(y)
if m != n || m == 0 {
switch {
case m < n:
r = -1
case m > n:
r = 1
}
return
}
i := m - 1
for i > 0 && x[i] == y[i] {
i--
}
switch {
case x[i] < y[i]:
r = -1
case x[i] > y[i]:
r = 1
}
return
} | go | func CmpBits(x, y []big.Word) (r int) {
// Copied from math/big.nat.go
m := len(x)
n := len(y)
if m != n || m == 0 {
switch {
case m < n:
r = -1
case m > n:
r = 1
}
return
}
i := m - 1
for i > 0 && x[i] == y[i] {
i--
}
switch {
case x[i] < y[i]:
r = -1
case x[i] > y[i]:
r = 1
}
return
} | [
"func",
"CmpBits",
"(",
"x",
",",
"y",
"[",
"]",
"big",
".",
"Word",
")",
"(",
"r",
"int",
")",
"{",
"// Copied from math/big.nat.go",
"m",
":=",
"len",
"(",
"x",
")",
"\n",
"n",
":=",
"len",
"(",
"y",
")",
"\n",
"if",
"m",
"!=",
"n",
"||",
"... | // CmpBits compares x and y. | [
"CmpBits",
"compares",
"x",
"and",
"y",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/abs.go#L37-L63 |
5,317 | ericlagergren/decimal | internal/arith/arith.go | Words | func Words(x uint64) []big.Word {
if bits.UintSize == 32 {
return []big.Word{big.Word(x), big.Word(x >> 32)}
}
return []big.Word{big.Word(x)}
} | go | func Words(x uint64) []big.Word {
if bits.UintSize == 32 {
return []big.Word{big.Word(x), big.Word(x >> 32)}
}
return []big.Word{big.Word(x)}
} | [
"func",
"Words",
"(",
"x",
"uint64",
")",
"[",
"]",
"big",
".",
"Word",
"{",
"if",
"bits",
".",
"UintSize",
"==",
"32",
"{",
"return",
"[",
"]",
"big",
".",
"Word",
"{",
"big",
".",
"Word",
"(",
"x",
")",
",",
"big",
".",
"Word",
"(",
"x",
... | // Words returns a little-endian slice of big.Words representing the uint64. | [
"Words",
"returns",
"a",
"little",
"-",
"endian",
"slice",
"of",
"big",
".",
"Words",
"representing",
"the",
"uint64",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L10-L15 |
5,318 | ericlagergren/decimal | internal/arith/arith.go | Add | func Add(z, x *big.Int, y uint64) *big.Int {
zw := z.Bits()
switch xw := x.Bits(); {
default:
zw = add(zw, xw, big.Word(y))
case len(xw) == 0:
zw = setW(zw, big.Word(y))
case y == 0:
zw = set(zw, xw)
}
return z.SetBits(zw)
} | go | func Add(z, x *big.Int, y uint64) *big.Int {
zw := z.Bits()
switch xw := x.Bits(); {
default:
zw = add(zw, xw, big.Word(y))
case len(xw) == 0:
zw = setW(zw, big.Word(y))
case y == 0:
zw = set(zw, xw)
}
return z.SetBits(zw)
} | [
"func",
"Add",
"(",
"z",
",",
"x",
"*",
"big",
".",
"Int",
",",
"y",
"uint64",
")",
"*",
"big",
".",
"Int",
"{",
"zw",
":=",
"z",
".",
"Bits",
"(",
")",
"\n",
"switch",
"xw",
":=",
"x",
".",
"Bits",
"(",
")",
";",
"{",
"default",
":",
"zw... | // Add sets z to x + y and returns z.
//
// x is assumed to be unsigned. | [
"Add",
"sets",
"z",
"to",
"x",
"+",
"y",
"and",
"returns",
"z",
".",
"x",
"is",
"assumed",
"to",
"be",
"unsigned",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L20-L31 |
5,319 | ericlagergren/decimal | internal/arith/arith.go | Sub | func Sub(z, x *big.Int, y uint64) *big.Int {
zw := z.Bits()
switch xw := x.Bits(); {
default:
zw = sub(zw, xw, big.Word(y))
case y == 0:
zw = set(zw, xw)
case len(xw) == 0:
panic("underflow")
}
return z.SetBits(zw)
} | go | func Sub(z, x *big.Int, y uint64) *big.Int {
zw := z.Bits()
switch xw := x.Bits(); {
default:
zw = sub(zw, xw, big.Word(y))
case y == 0:
zw = set(zw, xw)
case len(xw) == 0:
panic("underflow")
}
return z.SetBits(zw)
} | [
"func",
"Sub",
"(",
"z",
",",
"x",
"*",
"big",
".",
"Int",
",",
"y",
"uint64",
")",
"*",
"big",
".",
"Int",
"{",
"zw",
":=",
"z",
".",
"Bits",
"(",
")",
"\n",
"switch",
"xw",
":=",
"x",
".",
"Bits",
"(",
")",
";",
"{",
"default",
":",
"zw... | // Sub sets z to x - y and returns z.
//
// x is assumed to be unsigned. | [
"Sub",
"sets",
"z",
"to",
"x",
"-",
"y",
"and",
"returns",
"z",
".",
"x",
"is",
"assumed",
"to",
"be",
"unsigned",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L36-L47 |
5,320 | ericlagergren/decimal | internal/arith/arith.go | Set | func Set(z *big.Int, z1, z0 uint64) *big.Int {
ww := makeWord(z.Bits(), 128/bits.UintSize)
if bits.UintSize == 32 {
ww[3] = big.Word(z1 >> 32)
ww[2] = big.Word(z1)
ww[1] = big.Word(z0 >> 32)
ww[0] = big.Word(z0)
} else {
ww[1] = big.Word(z1)
ww[0] = big.Word(z0)
}
return z.SetBits(ww)
} | go | func Set(z *big.Int, z1, z0 uint64) *big.Int {
ww := makeWord(z.Bits(), 128/bits.UintSize)
if bits.UintSize == 32 {
ww[3] = big.Word(z1 >> 32)
ww[2] = big.Word(z1)
ww[1] = big.Word(z0 >> 32)
ww[0] = big.Word(z0)
} else {
ww[1] = big.Word(z1)
ww[0] = big.Word(z0)
}
return z.SetBits(ww)
} | [
"func",
"Set",
"(",
"z",
"*",
"big",
".",
"Int",
",",
"z1",
",",
"z0",
"uint64",
")",
"*",
"big",
".",
"Int",
"{",
"ww",
":=",
"makeWord",
"(",
"z",
".",
"Bits",
"(",
")",
",",
"128",
"/",
"bits",
".",
"UintSize",
")",
"\n",
"if",
"bits",
"... | // Set sets z to the 128-bit integer represented by z1 and z0. | [
"Set",
"sets",
"z",
"to",
"the",
"128",
"-",
"bit",
"integer",
"represented",
"by",
"z1",
"and",
"z0",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L84-L96 |
5,321 | ericlagergren/decimal | internal/arith/arith.go | add | func add(z, x []big.Word, y big.Word) []big.Word {
m := len(x)
const n = 1
// m > 0 && y > 0
z = makeWord(z, m+1)
var c big.Word
// addVV(z[0:m], x, y) but WW since len(y) == 1
c, z[0] = addWW(x[0], y, 0)
if m > n {
c = addVW(z[n:m], x[n:], c)
}
z[m] = c
return norm(z)
} | go | func add(z, x []big.Word, y big.Word) []big.Word {
m := len(x)
const n = 1
// m > 0 && y > 0
z = makeWord(z, m+1)
var c big.Word
// addVV(z[0:m], x, y) but WW since len(y) == 1
c, z[0] = addWW(x[0], y, 0)
if m > n {
c = addVW(z[n:m], x[n:], c)
}
z[m] = c
return norm(z)
} | [
"func",
"add",
"(",
"z",
",",
"x",
"[",
"]",
"big",
".",
"Word",
",",
"y",
"big",
".",
"Word",
")",
"[",
"]",
"big",
".",
"Word",
"{",
"m",
":=",
"len",
"(",
"x",
")",
"\n",
"const",
"n",
"=",
"1",
"\n\n",
"// m > 0 && y > 0",
"z",
"=",
"ma... | // add sets z to x + y and returns z. | [
"add",
"sets",
"z",
"to",
"x",
"+",
"y",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L165-L180 |
5,322 | ericlagergren/decimal | internal/arith/arith.go | sub | func sub(z, x []big.Word, y big.Word) []big.Word {
m := len(x)
const n = 1
// m > 0 && y > 0
z = makeWord(z, m)
// subVV(z[0:m], x, y) but WW since len(y) == 1
var c big.Word
c, z[0] = subWW(x[0], y, 0)
if m > n {
c = subVW(z[n:], x[n:], c)
}
if c != 0 {
panic("underflow")
}
return norm(z)
} | go | func sub(z, x []big.Word, y big.Word) []big.Word {
m := len(x)
const n = 1
// m > 0 && y > 0
z = makeWord(z, m)
// subVV(z[0:m], x, y) but WW since len(y) == 1
var c big.Word
c, z[0] = subWW(x[0], y, 0)
if m > n {
c = subVW(z[n:], x[n:], c)
}
if c != 0 {
panic("underflow")
}
return norm(z)
} | [
"func",
"sub",
"(",
"z",
",",
"x",
"[",
"]",
"big",
".",
"Word",
",",
"y",
"big",
".",
"Word",
")",
"[",
"]",
"big",
".",
"Word",
"{",
"m",
":=",
"len",
"(",
"x",
")",
"\n",
"const",
"n",
"=",
"1",
"\n\n",
"// m > 0 && y > 0",
"z",
"=",
"ma... | // sub sets z to x - y and returns z. | [
"sub",
"sets",
"z",
"to",
"x",
"-",
"y",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L183-L200 |
5,323 | ericlagergren/decimal | internal/arith/arith.go | addVW | func addVW(z, x []big.Word, y big.Word) (c big.Word) {
c = y
for i, xi := range x[:len(z)] {
zi := xi + c
z[i] = zi
c = xi &^ zi >> (bits.UintSize - 1)
}
return c
} | go | func addVW(z, x []big.Word, y big.Word) (c big.Word) {
c = y
for i, xi := range x[:len(z)] {
zi := xi + c
z[i] = zi
c = xi &^ zi >> (bits.UintSize - 1)
}
return c
} | [
"func",
"addVW",
"(",
"z",
",",
"x",
"[",
"]",
"big",
".",
"Word",
",",
"y",
"big",
".",
"Word",
")",
"(",
"c",
"big",
".",
"Word",
")",
"{",
"c",
"=",
"y",
"\n",
"for",
"i",
",",
"xi",
":=",
"range",
"x",
"[",
":",
"len",
"(",
"z",
")"... | // addVW sets z to x + y and returns the carry. | [
"addVW",
"sets",
"z",
"to",
"x",
"+",
"y",
"and",
"returns",
"the",
"carry",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/arith.go#L203-L211 |
5,324 | ericlagergren/decimal | math/const.go | E | func E(z *decimal.Big) *decimal.Big {
ctx := decimal.Context{Precision: precision(z)}
if ctx.Precision <= constPrec {
return ctx.Set(z, _E)
}
ctx.Precision += 5
var (
sum = z.SetUint64(2)
fac = new(decimal.Big).SetUint64(1)
term = new(decimal.Big)
prev = new(decimal.Big)
)
for i := uint64(2); sum.Cmp(prev) != 0; i++ {
// Use term as our intermediate storage for our factorial. SetUint64
// should be marginally faster than ctx.Add(incr, incr, one), but either
// the costly call to Quo makes it difficult to notice.
term.SetUint64(i)
ctx.Mul(fac, fac, term)
ctx.Quo(term, one, fac)
prev.Copy(sum)
ctx.Add(sum, sum, term)
}
ctx.Precision -= 5
return ctx.Set(z, sum)
} | go | func E(z *decimal.Big) *decimal.Big {
ctx := decimal.Context{Precision: precision(z)}
if ctx.Precision <= constPrec {
return ctx.Set(z, _E)
}
ctx.Precision += 5
var (
sum = z.SetUint64(2)
fac = new(decimal.Big).SetUint64(1)
term = new(decimal.Big)
prev = new(decimal.Big)
)
for i := uint64(2); sum.Cmp(prev) != 0; i++ {
// Use term as our intermediate storage for our factorial. SetUint64
// should be marginally faster than ctx.Add(incr, incr, one), but either
// the costly call to Quo makes it difficult to notice.
term.SetUint64(i)
ctx.Mul(fac, fac, term)
ctx.Quo(term, one, fac)
prev.Copy(sum)
ctx.Add(sum, sum, term)
}
ctx.Precision -= 5
return ctx.Set(z, sum)
} | [
"func",
"E",
"(",
"z",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"ctx",
":=",
"decimal",
".",
"Context",
"{",
"Precision",
":",
"precision",
"(",
"z",
")",
"}",
"\n",
"if",
"ctx",
".",
"Precision",
"<=",
"constPrec",
"{",
... | // E sets z to the mathematical constant e and returns z. | [
"E",
"sets",
"z",
"to",
"the",
"mathematical",
"constant",
"e",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/const.go#L33-L60 |
5,325 | ericlagergren/decimal | math/const.go | Pi | func Pi(z *decimal.Big) *decimal.Big {
return pi(z, decimal.Context{Precision: precision(z)})
} | go | func Pi(z *decimal.Big) *decimal.Big {
return pi(z, decimal.Context{Precision: precision(z)})
} | [
"func",
"Pi",
"(",
"z",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"return",
"pi",
"(",
"z",
",",
"decimal",
".",
"Context",
"{",
"Precision",
":",
"precision",
"(",
"z",
")",
"}",
")",
"\n",
"}"
] | // Pi sets z to the mathematical constant pi and returns z. | [
"Pi",
"sets",
"z",
"to",
"the",
"mathematical",
"constant",
"pi",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/const.go#L71-L73 |
5,326 | ericlagergren/decimal | math/const.go | pi | func pi(z *decimal.Big, ctx decimal.Context) *decimal.Big {
if ctx.Precision <= constPrec {
return ctx.Set(z, _Pi)
}
var (
lasts = new(decimal.Big)
t = new(decimal.Big).SetUint64(3)
s = z.SetUint64(3)
n = new(decimal.Big).SetUint64(1)
na = new(decimal.Big)
d = new(decimal.Big)
da = new(decimal.Big).SetUint64(24)
)
for s.Cmp(lasts) != 0 {
lasts.Copy(s)
ctx.Add(n, n, na)
ctx.Add(na, na, eight)
ctx.Add(d, d, da)
ctx.Add(da, da, thirtyTwo)
ctx.Mul(t, t, n)
ctx.Quo(t, t, d)
ctx.Add(s, s, t)
}
return ctx.Round(z) // z == s
} | go | func pi(z *decimal.Big, ctx decimal.Context) *decimal.Big {
if ctx.Precision <= constPrec {
return ctx.Set(z, _Pi)
}
var (
lasts = new(decimal.Big)
t = new(decimal.Big).SetUint64(3)
s = z.SetUint64(3)
n = new(decimal.Big).SetUint64(1)
na = new(decimal.Big)
d = new(decimal.Big)
da = new(decimal.Big).SetUint64(24)
)
for s.Cmp(lasts) != 0 {
lasts.Copy(s)
ctx.Add(n, n, na)
ctx.Add(na, na, eight)
ctx.Add(d, d, da)
ctx.Add(da, da, thirtyTwo)
ctx.Mul(t, t, n)
ctx.Quo(t, t, d)
ctx.Add(s, s, t)
}
return ctx.Round(z) // z == s
} | [
"func",
"pi",
"(",
"z",
"*",
"decimal",
".",
"Big",
",",
"ctx",
"decimal",
".",
"Context",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"ctx",
".",
"Precision",
"<=",
"constPrec",
"{",
"return",
"ctx",
".",
"Set",
"(",
"z",
",",
"_Pi",
")",
"\n",
... | // pi sets z to the mathematical constant pi and returns z. | [
"pi",
"sets",
"z",
"to",
"the",
"mathematical",
"constant",
"pi",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/const.go#L76-L102 |
5,327 | ericlagergren/decimal | internal/arith/pow.go | PowOfTenBig | func PowOfTenBig(x *big.Int) bool {
if x.Bit(0) != 0 {
return x.Cmp(c.OneInt) == 0
}
if x.Sign() == 0 {
return true
}
q := new(big.Int).Set(x)
r := new(big.Int)
for len := BigLength(x); len > 20; len-- {
q.QuoRem(q, c.TenInt, r)
if r.Sign() != 0 {
return false
}
}
return PowOfTen(q.Uint64())
} | go | func PowOfTenBig(x *big.Int) bool {
if x.Bit(0) != 0 {
return x.Cmp(c.OneInt) == 0
}
if x.Sign() == 0 {
return true
}
q := new(big.Int).Set(x)
r := new(big.Int)
for len := BigLength(x); len > 20; len-- {
q.QuoRem(q, c.TenInt, r)
if r.Sign() != 0 {
return false
}
}
return PowOfTen(q.Uint64())
} | [
"func",
"PowOfTenBig",
"(",
"x",
"*",
"big",
".",
"Int",
")",
"bool",
"{",
"if",
"x",
".",
"Bit",
"(",
"0",
")",
"!=",
"0",
"{",
"return",
"x",
".",
"Cmp",
"(",
"c",
".",
"OneInt",
")",
"==",
"0",
"\n",
"}",
"\n",
"if",
"x",
".",
"Sign",
... | // PowOfTenBig returns true if x is a power of 10. | [
"PowOfTenBig",
"returns",
"true",
"if",
"x",
"is",
"a",
"power",
"of",
"10",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/internal/arith/pow.go#L50-L66 |
5,328 | ericlagergren/decimal | math/floor.go | Floor | func Floor(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
ctx := z.Context
ctx.RoundingMode = decimal.ToNegativeInf
return ctx.RoundToInt(z.Copy(x))
} | go | func Floor(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
ctx := z.Context
ctx.RoundingMode = decimal.ToNegativeInf
return ctx.RoundToInt(z.Copy(x))
} | [
"func",
"Floor",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"z",
".",
"CheckNaNs",
"(",
"x",
",",
"nil",
")",
"{",
"return",
"z",
"\n",
"}",
"\n",
"ctx",
":=",
"z",
".",
"Context",
"\n",
"ctx",... | // Floor sets z to the greatest integer value less than or equal to x and returns
// z. | [
"Floor",
"sets",
"z",
"to",
"the",
"greatest",
"integer",
"value",
"less",
"than",
"or",
"equal",
"to",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/floor.go#L10-L17 |
5,329 | ericlagergren/decimal | math/floor.go | Ceil | func Ceil(z, x *decimal.Big) *decimal.Big {
// ceil(x) = -floor(-x)
return z.Neg(Floor(z, misc.CopyNeg(z, x)))
} | go | func Ceil(z, x *decimal.Big) *decimal.Big {
// ceil(x) = -floor(-x)
return z.Neg(Floor(z, misc.CopyNeg(z, x)))
} | [
"func",
"Ceil",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"// ceil(x) = -floor(-x)",
"return",
"z",
".",
"Neg",
"(",
"Floor",
"(",
"z",
",",
"misc",
".",
"CopyNeg",
"(",
"z",
",",
"x",
")",
")",
")",
... | // Ceil sets z to the least integer value greater than or equal to x and returns
// z. | [
"Ceil",
"sets",
"z",
"to",
"the",
"least",
"integer",
"value",
"greater",
"than",
"or",
"equal",
"to",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/floor.go#L21-L24 |
5,330 | ericlagergren/decimal | format.go | allZeros | func allZeros(b []byte) bool {
for _, c := range b {
if c != '0' {
return false
}
}
return true
} | go | func allZeros(b []byte) bool {
for _, c := range b {
if c != '0' {
return false
}
}
return true
} | [
"func",
"allZeros",
"(",
"b",
"[",
"]",
"byte",
")",
"bool",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"b",
"{",
"if",
"c",
"!=",
"'0'",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // allZeros returns true if every character in b is '0'. | [
"allZeros",
"returns",
"true",
"if",
"every",
"character",
"in",
"b",
"is",
"0",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/format.go#L12-L19 |
5,331 | ericlagergren/decimal | format.go | formatCompact | func formatCompact(x uint64) []byte {
var b [20]byte
return strconv.AppendUint(b[0:0], uint64(x), 10)
} | go | func formatCompact(x uint64) []byte {
var b [20]byte
return strconv.AppendUint(b[0:0], uint64(x), 10)
} | [
"func",
"formatCompact",
"(",
"x",
"uint64",
")",
"[",
"]",
"byte",
"{",
"var",
"b",
"[",
"20",
"]",
"byte",
"\n",
"return",
"strconv",
".",
"AppendUint",
"(",
"b",
"[",
"0",
":",
"0",
"]",
",",
"uint64",
"(",
"x",
")",
",",
"10",
")",
"\n",
... | // formatCompact formats the compact decimal, x, as an unsigned integer. | [
"formatCompact",
"formats",
"the",
"compact",
"decimal",
"x",
"as",
"an",
"unsigned",
"integer",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/format.go#L91-L94 |
5,332 | ericlagergren/decimal | format.go | formatSci | func (f *formatter) formatSci(b []byte, adj int, e byte) {
f.WriteByte(b[0])
if len(b) > 1 {
f.WriteByte('.')
f.Write(b[1:])
}
// If negative, the call to strconv.Itoa will add the minus sign for us.
f.WriteByte(e)
if adj > 0 {
f.WriteByte('+')
}
f.WriteString(strconv.Itoa(adj))
} | go | func (f *formatter) formatSci(b []byte, adj int, e byte) {
f.WriteByte(b[0])
if len(b) > 1 {
f.WriteByte('.')
f.Write(b[1:])
}
// If negative, the call to strconv.Itoa will add the minus sign for us.
f.WriteByte(e)
if adj > 0 {
f.WriteByte('+')
}
f.WriteString(strconv.Itoa(adj))
} | [
"func",
"(",
"f",
"*",
"formatter",
")",
"formatSci",
"(",
"b",
"[",
"]",
"byte",
",",
"adj",
"int",
",",
"e",
"byte",
")",
"{",
"f",
".",
"WriteByte",
"(",
"b",
"[",
"0",
"]",
")",
"\n\n",
"if",
"len",
"(",
"b",
")",
">",
"1",
"{",
"f",
... | // formatSci returns the scientific version of b. | [
"formatSci",
"returns",
"the",
"scientific",
"version",
"of",
"b",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/format.go#L244-L258 |
5,333 | ericlagergren/decimal | format.go | formatPlain | func (f *formatter) formatPlain(b []byte, exp int) {
const zeroRadix = "0."
switch radix := len(b) + exp; {
// log10(b) == scale, so immediately before b: 0.123456
case radix == 0:
f.WriteString(zeroRadix)
f.Write(b)
// log10(b) > scale, so somewhere inside b: 123.456
case radix > 0:
f.Write(b[:radix])
if radix < len(b) {
f.WriteByte('.')
f.Write(b[radix:])
}
// log10(b) < scale, so before p "0s" and before b: 0.00000123456
default:
f.WriteString(zeroRadix)
io.CopyN(f, zeroReader{}, -int64(radix))
end := len(b)
if f.prec < end {
end = f.prec
}
f.Write(b[:end])
}
} | go | func (f *formatter) formatPlain(b []byte, exp int) {
const zeroRadix = "0."
switch radix := len(b) + exp; {
// log10(b) == scale, so immediately before b: 0.123456
case radix == 0:
f.WriteString(zeroRadix)
f.Write(b)
// log10(b) > scale, so somewhere inside b: 123.456
case radix > 0:
f.Write(b[:radix])
if radix < len(b) {
f.WriteByte('.')
f.Write(b[radix:])
}
// log10(b) < scale, so before p "0s" and before b: 0.00000123456
default:
f.WriteString(zeroRadix)
io.CopyN(f, zeroReader{}, -int64(radix))
end := len(b)
if f.prec < end {
end = f.prec
}
f.Write(b[:end])
}
} | [
"func",
"(",
"f",
"*",
"formatter",
")",
"formatPlain",
"(",
"b",
"[",
"]",
"byte",
",",
"exp",
"int",
")",
"{",
"const",
"zeroRadix",
"=",
"\"",
"\"",
"\n\n",
"switch",
"radix",
":=",
"len",
"(",
"b",
")",
"+",
"exp",
";",
"{",
"// log10(b) == sca... | // formatPlain returns the plain string version of b. | [
"formatPlain",
"returns",
"the",
"plain",
"string",
"version",
"of",
"b",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/format.go#L261-L289 |
5,334 | ericlagergren/decimal | util.go | alias | func alias(z, x *big.Int) *big.Int {
if z != x {
// We have to check the first element of their internal slices since
// Big doesn't store a pointer to a big.Int.
zb, xb := z.Bits(), x.Bits()
if cap(zb) > 0 && cap(xb) > 0 && &zb[0:cap(zb)][cap(zb)-1] != &xb[0:cap(xb)][cap(xb)-1] {
return z
}
}
return new(big.Int)
} | go | func alias(z, x *big.Int) *big.Int {
if z != x {
// We have to check the first element of their internal slices since
// Big doesn't store a pointer to a big.Int.
zb, xb := z.Bits(), x.Bits()
if cap(zb) > 0 && cap(xb) > 0 && &zb[0:cap(zb)][cap(zb)-1] != &xb[0:cap(xb)][cap(xb)-1] {
return z
}
}
return new(big.Int)
} | [
"func",
"alias",
"(",
"z",
",",
"x",
"*",
"big",
".",
"Int",
")",
"*",
"big",
".",
"Int",
"{",
"if",
"z",
"!=",
"x",
"{",
"// We have to check the first element of their internal slices since",
"// Big doesn't store a pointer to a big.Int.",
"zb",
",",
"xb",
":=",... | // alias returns z if z != x, otherwise a newly-allocated big.Int. | [
"alias",
"returns",
"z",
"if",
"z",
"!",
"=",
"x",
"otherwise",
"a",
"newly",
"-",
"allocated",
"big",
".",
"Int",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/util.go#L80-L90 |
5,335 | ericlagergren/decimal | util.go | bigScalex | func bigScalex(z, x *big.Int, scale int) *big.Int {
if scale > 0 {
return arith.MulBigPow10(z, x, uint64(scale))
}
return z.Quo(x, arith.BigPow10(uint64(-scale)))
} | go | func bigScalex(z, x *big.Int, scale int) *big.Int {
if scale > 0 {
return arith.MulBigPow10(z, x, uint64(scale))
}
return z.Quo(x, arith.BigPow10(uint64(-scale)))
} | [
"func",
"bigScalex",
"(",
"z",
",",
"x",
"*",
"big",
".",
"Int",
",",
"scale",
"int",
")",
"*",
"big",
".",
"Int",
"{",
"if",
"scale",
">",
"0",
"{",
"return",
"arith",
".",
"MulBigPow10",
"(",
"z",
",",
"x",
",",
"uint64",
"(",
"scale",
")",
... | // bigScalex sets z to the big.Int equivalient of scalex. | [
"bigScalex",
"sets",
"z",
"to",
"the",
"big",
".",
"Int",
"equivalient",
"of",
"scalex",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/util.go#L188-L193 |
5,336 | ericlagergren/decimal | math/sqrt.go | Sqrt | func Sqrt(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
ideal := -((-x.Scale() - (-x.Scale() & 1)) / 2)
if xs := x.Sign(); xs <= 0 {
if xs == 0 {
return z.SetMantScale(0, ideal).CopySign(z, x)
}
z.Context.Conditions |= decimal.InvalidOperation
return z.SetNaN(false)
}
// Already checked for negative numbers.
if x.IsInf(+1) {
return z.SetInf(false)
}
var (
prec = precision(z)
ctx = decimal.Context{Precision: prec}
rnd = z.Context.Conditions&decimal.Rounded != 0
ixt = z.Context.Conditions&decimal.Inexact != 0
)
// Source for the following algorithm:
//
// T. E. Hull and A. Abrham. 1985. Properly rounded variable precision
// square root. ACM Trans. Math. Softw. 11, 3 (September 1985), 229-237.
// DOI: https://doi.org/10.1145/214408.214413
var (
xprec = x.Precision()
// The algorithm requires a normalized ``f ∈ [0.1, 1)'' Of the two ways
// to normalize f, adjusting its scale is the quickest. However, it then
// requires us to increment approx's scale by e/2 instead of simply
// setting it to e/2.
f = new(decimal.Big).Copy(x).SetScale(xprec)
e = -x.Scale() + xprec
tmp decimal.Big // scratch space
)
if e&1 == 0 {
ctx.FMA(z, approx2, f, approx1) // approx := .259 + .819f
} else {
f.SetScale(f.Scale() + 1) // f := f/10
e++ // e := e + 1
ctx.FMA(z, approx4, f, approx3) // approx := .0819 + 2.59f
}
maxp := prec + 5 // extra prec to skip weird +/- 0.5 adjustments
ctx.Precision = 3
for {
// p := min(2*p - 2, maxp)
ctx.Precision = min(2*ctx.Precision-2, maxp)
// approx := .5*(approx + f/approx)
ctx.Mul(z, ptFive, ctx.Add(&tmp, z, ctx.Quo(&tmp, f, z)))
if ctx.Precision == maxp {
break
}
}
// The paper also specifies an additional code block for adjusting approx.
// This code never went into the branches that modified approx, and rounding
// to half even does the same thing. The GDA spec requires us to use
// rounding mode half even (speleotrove.com/decimal/daops.html#refsqrt)
// anyway.
ctx.Reduce(z.SetScale(z.Scale() - e/2))
if z.Precision() <= prec {
if !rnd {
z.Context.Conditions &= ^decimal.Rounded
}
if !ixt {
z.Context.Conditions &= ^decimal.Inexact
}
}
ctx.Precision = prec
return ctx.Round(z)
} | go | func Sqrt(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
ideal := -((-x.Scale() - (-x.Scale() & 1)) / 2)
if xs := x.Sign(); xs <= 0 {
if xs == 0 {
return z.SetMantScale(0, ideal).CopySign(z, x)
}
z.Context.Conditions |= decimal.InvalidOperation
return z.SetNaN(false)
}
// Already checked for negative numbers.
if x.IsInf(+1) {
return z.SetInf(false)
}
var (
prec = precision(z)
ctx = decimal.Context{Precision: prec}
rnd = z.Context.Conditions&decimal.Rounded != 0
ixt = z.Context.Conditions&decimal.Inexact != 0
)
// Source for the following algorithm:
//
// T. E. Hull and A. Abrham. 1985. Properly rounded variable precision
// square root. ACM Trans. Math. Softw. 11, 3 (September 1985), 229-237.
// DOI: https://doi.org/10.1145/214408.214413
var (
xprec = x.Precision()
// The algorithm requires a normalized ``f ∈ [0.1, 1)'' Of the two ways
// to normalize f, adjusting its scale is the quickest. However, it then
// requires us to increment approx's scale by e/2 instead of simply
// setting it to e/2.
f = new(decimal.Big).Copy(x).SetScale(xprec)
e = -x.Scale() + xprec
tmp decimal.Big // scratch space
)
if e&1 == 0 {
ctx.FMA(z, approx2, f, approx1) // approx := .259 + .819f
} else {
f.SetScale(f.Scale() + 1) // f := f/10
e++ // e := e + 1
ctx.FMA(z, approx4, f, approx3) // approx := .0819 + 2.59f
}
maxp := prec + 5 // extra prec to skip weird +/- 0.5 adjustments
ctx.Precision = 3
for {
// p := min(2*p - 2, maxp)
ctx.Precision = min(2*ctx.Precision-2, maxp)
// approx := .5*(approx + f/approx)
ctx.Mul(z, ptFive, ctx.Add(&tmp, z, ctx.Quo(&tmp, f, z)))
if ctx.Precision == maxp {
break
}
}
// The paper also specifies an additional code block for adjusting approx.
// This code never went into the branches that modified approx, and rounding
// to half even does the same thing. The GDA spec requires us to use
// rounding mode half even (speleotrove.com/decimal/daops.html#refsqrt)
// anyway.
ctx.Reduce(z.SetScale(z.Scale() - e/2))
if z.Precision() <= prec {
if !rnd {
z.Context.Conditions &= ^decimal.Rounded
}
if !ixt {
z.Context.Conditions &= ^decimal.Inexact
}
}
ctx.Precision = prec
return ctx.Round(z)
} | [
"func",
"Sqrt",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"z",
".",
"CheckNaNs",
"(",
"x",
",",
"nil",
")",
"{",
"return",
"z",
"\n",
"}",
"\n\n",
"ideal",
":=",
"-",
"(",
"(",
"-",
"x",
"."... | // Sqrt sets z to the square root of x and returns z. | [
"Sqrt",
"sets",
"z",
"to",
"the",
"square",
"root",
"of",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/sqrt.go#L34-L117 |
5,337 | ericlagergren/decimal | context.go | Err | func (c Context) Err() error {
if m := c.Conditions & c.Traps; m != 0 {
return m
}
return nil
} | go | func (c Context) Err() error {
if m := c.Conditions & c.Traps; m != 0 {
return m
}
return nil
} | [
"func",
"(",
"c",
"Context",
")",
"Err",
"(",
")",
"error",
"{",
"if",
"m",
":=",
"c",
".",
"Conditions",
"&",
"c",
".",
"Traps",
";",
"m",
"!=",
"0",
"{",
"return",
"m",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Err returns non-nil if there are any trapped exceptional conditions. | [
"Err",
"returns",
"non",
"-",
"nil",
"if",
"there",
"are",
"any",
"trapped",
"exceptional",
"conditions",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/context.go#L74-L79 |
5,338 | ericlagergren/decimal | context.go | WithContext | func WithContext(c Context) *Big {
z := new(Big)
z.Context = c
return z
} | go | func WithContext(c Context) *Big {
z := new(Big)
z.Context = c
return z
} | [
"func",
"WithContext",
"(",
"c",
"Context",
")",
"*",
"Big",
"{",
"z",
":=",
"new",
"(",
"Big",
")",
"\n",
"z",
".",
"Context",
"=",
"c",
"\n",
"return",
"z",
"\n",
"}"
] | // WithContext is shorthand to create a Big decimal from a Context. | [
"WithContext",
"is",
"shorthand",
"to",
"create",
"a",
"Big",
"decimal",
"from",
"a",
"Context",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/context.go#L82-L86 |
5,339 | ericlagergren/decimal | context.go | WithPrecision | func WithPrecision(p int) *Big {
z := new(Big)
switch {
case p > 0 && p <= UnlimitedPrecision:
z.Context.Precision = p
case p == 0:
z.Context.Precision = DefaultPrecision
default:
z.setNaN(InvalidContext, qnan, invctxpgtu)
}
return z
} | go | func WithPrecision(p int) *Big {
z := new(Big)
switch {
case p > 0 && p <= UnlimitedPrecision:
z.Context.Precision = p
case p == 0:
z.Context.Precision = DefaultPrecision
default:
z.setNaN(InvalidContext, qnan, invctxpgtu)
}
return z
} | [
"func",
"WithPrecision",
"(",
"p",
"int",
")",
"*",
"Big",
"{",
"z",
":=",
"new",
"(",
"Big",
")",
"\n",
"switch",
"{",
"case",
"p",
">",
"0",
"&&",
"p",
"<=",
"UnlimitedPrecision",
":",
"z",
".",
"Context",
".",
"Precision",
"=",
"p",
"\n",
"cas... | // WithPrecision is shorthand to create a Big decimal with a given precision. | [
"WithPrecision",
"is",
"shorthand",
"to",
"create",
"a",
"Big",
"decimal",
"with",
"a",
"given",
"precision",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/context.go#L89-L100 |
5,340 | ericlagergren/decimal | big_ctx.go | Add | func (c Context) Add(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
z.form = c.add(z, x, x.form, y, y.form)
return c.round(z)
}
// NaN + NaN
// NaN + y
// x + NaN
if z.checkNaNs(x, y, addition) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 && x.form^y.form == signbit {
// +Inf + -Inf
// -Inf + +Inf
return z.setNaN(InvalidOperation, qnan, addinfinf)
}
// ±Inf + y
// +Inf + +Inf
// -Inf + -Inf
return z.Set(x)
}
// x + ±Inf
return z.Set(y)
} | go | func (c Context) Add(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
z.form = c.add(z, x, x.form, y, y.form)
return c.round(z)
}
// NaN + NaN
// NaN + y
// x + NaN
if z.checkNaNs(x, y, addition) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 && x.form^y.form == signbit {
// +Inf + -Inf
// -Inf + +Inf
return z.setNaN(InvalidOperation, qnan, addinfinf)
}
// ±Inf + y
// +Inf + +Inf
// -Inf + -Inf
return z.Set(x)
}
// x + ±Inf
return z.Set(y)
} | [
"func",
"(",
"c",
"Context",
")",
"Add",
"(",
"z",
",",
"x",
",",
"y",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"z",
".",
"invalidCont... | // Add sets z to x + y and returns z. | [
"Add",
"sets",
"z",
"to",
"x",
"+",
"y",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L12-L46 |
5,341 | ericlagergren/decimal | big_ctx.go | mul | func (c Context) mul(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
sign := x.form&signbit ^ y.form&signbit
if x.IsFinite() && y.IsFinite() {
z.form = finite | sign
z.exp = x.exp + y.exp
// Multiplication is simple, so inline it.
if x.isCompact() {
if y.isCompact() {
hi, lo := arith.Mul64(x.compact, y.compact)
if hi == 0 {
z.compact = lo
if lo == cst.Inflated {
z.unscaled.SetUint64(cst.Inflated)
}
z.precision = arith.Length(lo)
return z
}
arith.Set(&z.unscaled, hi, lo)
} else { // y.isInflated
arith.Mul(&z.unscaled, &y.unscaled, x.compact)
}
} else if y.isCompact() { // x.isInflated
arith.Mul(&z.unscaled, &x.unscaled, y.compact)
} else {
z.unscaled.Mul(&x.unscaled, &y.unscaled)
}
return z.norm()
}
// NaN * NaN
// NaN * y
// x * NaN
if z.checkNaNs(x, y, multiplication) {
return z
}
if (x.IsInf(0) && !y.isZero()) ||
(y.IsInf(0) && !x.isZero()) ||
(y.IsInf(0) && x.IsInf(0)) {
// ±Inf * y
// x * ±Inf
// ±Inf * ±Inf
return z.SetInf(sign != 0)
}
// 0 * ±Inf
// ±Inf * 0
return z.setNaN(InvalidOperation, qnan, mul0inf)
} | go | func (c Context) mul(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
sign := x.form&signbit ^ y.form&signbit
if x.IsFinite() && y.IsFinite() {
z.form = finite | sign
z.exp = x.exp + y.exp
// Multiplication is simple, so inline it.
if x.isCompact() {
if y.isCompact() {
hi, lo := arith.Mul64(x.compact, y.compact)
if hi == 0 {
z.compact = lo
if lo == cst.Inflated {
z.unscaled.SetUint64(cst.Inflated)
}
z.precision = arith.Length(lo)
return z
}
arith.Set(&z.unscaled, hi, lo)
} else { // y.isInflated
arith.Mul(&z.unscaled, &y.unscaled, x.compact)
}
} else if y.isCompact() { // x.isInflated
arith.Mul(&z.unscaled, &x.unscaled, y.compact)
} else {
z.unscaled.Mul(&x.unscaled, &y.unscaled)
}
return z.norm()
}
// NaN * NaN
// NaN * y
// x * NaN
if z.checkNaNs(x, y, multiplication) {
return z
}
if (x.IsInf(0) && !y.isZero()) ||
(y.IsInf(0) && !x.isZero()) ||
(y.IsInf(0) && x.IsInf(0)) {
// ±Inf * y
// x * ±Inf
// ±Inf * ±Inf
return z.SetInf(sign != 0)
}
// 0 * ±Inf
// ±Inf * 0
return z.setNaN(InvalidOperation, qnan, mul0inf)
} | [
"func",
"(",
"c",
"Context",
")",
"mul",
"(",
"z",
",",
"x",
",",
"y",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"sign",
":=",
"x",
".",
... | // mul is the implementation of Mul. | [
"mul",
"is",
"the",
"implementation",
"of",
"Mul",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L316-L371 |
5,342 | ericlagergren/decimal | big_ctx.go | Quantize | func (c Context) Quantize(z *Big, n int) *Big {
if debug {
z.validate()
}
if z.invalidContext(c) {
return z
}
n = -n
if z.isSpecial() {
if z.form&inf != 0 {
return z.setNaN(InvalidOperation, qnan, quantinf)
}
z.checkNaNs(z, z, quantization)
return z
}
if n > c.maxScale() || n < c.etiny() {
return z.setNaN(InvalidOperation, qnan, quantminmax)
}
if z.isZero() {
z.exp = n
return z
}
shift := z.exp - n
if z.Precision()+shift > precision(c) {
return z.setNaN(InvalidOperation, qnan, quantprec)
}
z.exp = n
if shift == 0 {
return z
}
if shift < 0 {
z.Context.Conditions |= Rounded
}
m := c.RoundingMode
neg := z.form & signbit
if z.isCompact() {
if shift > 0 {
if zc, ok := arith.MulPow10(z.compact, uint64(shift)); ok {
return z.setTriple(zc, neg, n)
}
// shift < 0
} else if yc, ok := arith.Pow10(uint64(-shift)); ok {
z.quo(m, z.compact, neg, yc, 0)
return z
}
z.unscaled.SetUint64(z.compact)
z.compact = cst.Inflated
}
if shift > 0 {
arith.MulBigPow10(&z.unscaled, &z.unscaled, uint64(shift))
z.precision = arith.BigLength(&z.unscaled)
} else {
var r big.Int
z.quoBig(m, &z.unscaled, neg, arith.BigPow10(uint64(-shift)), 0, &r)
}
return z
} | go | func (c Context) Quantize(z *Big, n int) *Big {
if debug {
z.validate()
}
if z.invalidContext(c) {
return z
}
n = -n
if z.isSpecial() {
if z.form&inf != 0 {
return z.setNaN(InvalidOperation, qnan, quantinf)
}
z.checkNaNs(z, z, quantization)
return z
}
if n > c.maxScale() || n < c.etiny() {
return z.setNaN(InvalidOperation, qnan, quantminmax)
}
if z.isZero() {
z.exp = n
return z
}
shift := z.exp - n
if z.Precision()+shift > precision(c) {
return z.setNaN(InvalidOperation, qnan, quantprec)
}
z.exp = n
if shift == 0 {
return z
}
if shift < 0 {
z.Context.Conditions |= Rounded
}
m := c.RoundingMode
neg := z.form & signbit
if z.isCompact() {
if shift > 0 {
if zc, ok := arith.MulPow10(z.compact, uint64(shift)); ok {
return z.setTriple(zc, neg, n)
}
// shift < 0
} else if yc, ok := arith.Pow10(uint64(-shift)); ok {
z.quo(m, z.compact, neg, yc, 0)
return z
}
z.unscaled.SetUint64(z.compact)
z.compact = cst.Inflated
}
if shift > 0 {
arith.MulBigPow10(&z.unscaled, &z.unscaled, uint64(shift))
z.precision = arith.BigLength(&z.unscaled)
} else {
var r big.Int
z.quoBig(m, &z.unscaled, neg, arith.BigPow10(uint64(-shift)), 0, &r)
}
return z
} | [
"func",
"(",
"c",
"Context",
")",
"Quantize",
"(",
"z",
"*",
"Big",
",",
"n",
"int",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"z",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"z",
".",
"invalidContext",
"(",
"c",
")",
"{",
"return",
"z... | // Quantize sets z to the number equal in value and sign to z with the scale, n.
//
// In order to perform truncation, set the Context's RoundingMode to ToZero. | [
"Quantize",
"sets",
"z",
"to",
"the",
"number",
"equal",
"in",
"value",
"and",
"sign",
"to",
"z",
"with",
"the",
"scale",
"n",
".",
"In",
"order",
"to",
"perform",
"truncation",
"set",
"the",
"Context",
"s",
"RoundingMode",
"to",
"ToZero",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L376-L440 |
5,343 | ericlagergren/decimal | big_ctx.go | Reduce | func (c Context) Reduce(z *Big) *Big {
if debug {
z.validate()
}
c.Round(z)
return c.simpleReduce(z)
} | go | func (c Context) Reduce(z *Big) *Big {
if debug {
z.validate()
}
c.Round(z)
return c.simpleReduce(z)
} | [
"func",
"(",
"c",
"Context",
")",
"Reduce",
"(",
"z",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"z",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"c",
".",
"Round",
"(",
"z",
")",
"\n",
"return",
"c",
".",
"simpleReduce",
"(",
"z",... | // Reduce reduces a finite z to its most simplest form. | [
"Reduce",
"reduces",
"a",
"finite",
"z",
"to",
"its",
"most",
"simplest",
"form",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L880-L886 |
5,344 | ericlagergren/decimal | big_ctx.go | simpleReduce | func (c Context) simpleReduce(z *Big) *Big {
if z.isSpecial() {
// Same semantics as plus(z), i.e. z + 0.
z.checkNaNs(z, z, reduction)
return z
}
if z.isZero() {
z.exp = 0
z.precision = 1
return z
}
if z.compact == cst.Inflated {
if z.unscaled.Bit(0) != 0 {
return z
}
var r big.Int
for z.precision >= 20 {
z.unscaled.QuoRem(&z.unscaled, cst.OneMillionInt, &r)
if r.Sign() != 0 {
// TODO(eric): which is less expensive? Copying z.unscaled into
// a temporary or reconstructing if we can't divide by N?
z.unscaled.Mul(&z.unscaled, cst.OneMillionInt)
z.unscaled.Add(&z.unscaled, &r)
break
}
z.exp += 6
z.precision -= 6
// Try to avoid reconstruction for odd numbers.
if z.unscaled.Bit(0) != 0 {
break
}
}
for z.precision >= 20 {
z.unscaled.QuoRem(&z.unscaled, cst.TenInt, &r)
if r.Sign() != 0 {
z.unscaled.Mul(&z.unscaled, cst.TenInt)
z.unscaled.Add(&z.unscaled, &r)
break
}
z.exp++
z.precision--
if z.unscaled.Bit(0) != 0 {
break
}
}
if z.precision >= 20 {
return z.norm()
}
z.compact = z.unscaled.Uint64()
}
for ; z.compact >= 10000 && z.compact%10000 == 0; z.precision -= 4 {
z.compact /= 10000
z.exp += 4
}
for ; z.compact%10 == 0; z.precision-- {
z.compact /= 10
z.exp++
}
return z
} | go | func (c Context) simpleReduce(z *Big) *Big {
if z.isSpecial() {
// Same semantics as plus(z), i.e. z + 0.
z.checkNaNs(z, z, reduction)
return z
}
if z.isZero() {
z.exp = 0
z.precision = 1
return z
}
if z.compact == cst.Inflated {
if z.unscaled.Bit(0) != 0 {
return z
}
var r big.Int
for z.precision >= 20 {
z.unscaled.QuoRem(&z.unscaled, cst.OneMillionInt, &r)
if r.Sign() != 0 {
// TODO(eric): which is less expensive? Copying z.unscaled into
// a temporary or reconstructing if we can't divide by N?
z.unscaled.Mul(&z.unscaled, cst.OneMillionInt)
z.unscaled.Add(&z.unscaled, &r)
break
}
z.exp += 6
z.precision -= 6
// Try to avoid reconstruction for odd numbers.
if z.unscaled.Bit(0) != 0 {
break
}
}
for z.precision >= 20 {
z.unscaled.QuoRem(&z.unscaled, cst.TenInt, &r)
if r.Sign() != 0 {
z.unscaled.Mul(&z.unscaled, cst.TenInt)
z.unscaled.Add(&z.unscaled, &r)
break
}
z.exp++
z.precision--
if z.unscaled.Bit(0) != 0 {
break
}
}
if z.precision >= 20 {
return z.norm()
}
z.compact = z.unscaled.Uint64()
}
for ; z.compact >= 10000 && z.compact%10000 == 0; z.precision -= 4 {
z.compact /= 10000
z.exp += 4
}
for ; z.compact%10 == 0; z.precision-- {
z.compact /= 10
z.exp++
}
return z
} | [
"func",
"(",
"c",
"Context",
")",
"simpleReduce",
"(",
"z",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"z",
".",
"isSpecial",
"(",
")",
"{",
"// Same semantics as plus(z), i.e. z + 0.",
"z",
".",
"checkNaNs",
"(",
"z",
",",
"z",
",",
"reduction",
")",
"\n... | // simpleReduce is the same as Reduce, but it does not round prior to reducing
// the decimal. | [
"simpleReduce",
"is",
"the",
"same",
"as",
"Reduce",
"but",
"it",
"does",
"not",
"round",
"prior",
"to",
"reducing",
"the",
"decimal",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L890-L956 |
5,345 | ericlagergren/decimal | big_ctx.go | Rem | func (c Context) Rem(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
if y.isZero() {
if x.isZero() {
// 0 / 0
return z.setNaN(InvalidOperation|DivisionUndefined, qnan, quo00)
}
// x / 0
return z.setNaN(InvalidOperation|DivisionByZero, qnan, remx0)
}
if x.isZero() {
// 0 / y
return z.setZero(x.form&signbit, min(x.exp, y.exp))
}
// TODO(eric): See if we can get rid of tmp. See issue #72.
var tmp Big
_, z = c.quorem(&tmp, z, x, y)
z.exp = min(x.exp, y.exp)
tmp.exp = 0
if tmp.Precision() > precision(c) {
return z.setNaN(DivisionImpossible, qnan, quointprec)
}
return c.round(z)
}
// NaN / NaN
// NaN / y
// x / NaN
if z.checkNaNs(x, y, division) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 {
// ±Inf / ±Inf
return z.setNaN(InvalidOperation, qnan, quoinfinf)
}
// ±Inf / y
return z.setNaN(InvalidOperation, qnan, reminfy)
}
// x / ±Inf
return z.Set(x)
} | go | func (c Context) Rem(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
if y.isZero() {
if x.isZero() {
// 0 / 0
return z.setNaN(InvalidOperation|DivisionUndefined, qnan, quo00)
}
// x / 0
return z.setNaN(InvalidOperation|DivisionByZero, qnan, remx0)
}
if x.isZero() {
// 0 / y
return z.setZero(x.form&signbit, min(x.exp, y.exp))
}
// TODO(eric): See if we can get rid of tmp. See issue #72.
var tmp Big
_, z = c.quorem(&tmp, z, x, y)
z.exp = min(x.exp, y.exp)
tmp.exp = 0
if tmp.Precision() > precision(c) {
return z.setNaN(DivisionImpossible, qnan, quointprec)
}
return c.round(z)
}
// NaN / NaN
// NaN / y
// x / NaN
if z.checkNaNs(x, y, division) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 {
// ±Inf / ±Inf
return z.setNaN(InvalidOperation, qnan, quoinfinf)
}
// ±Inf / y
return z.setNaN(InvalidOperation, qnan, reminfy)
}
// x / ±Inf
return z.Set(x)
} | [
"func",
"(",
"c",
"Context",
")",
"Rem",
"(",
"z",
",",
"x",
",",
"y",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"z",
".",
"invalidCont... | // Rem sets z to the remainder x % y. See QuoRem for more details. | [
"Rem",
"sets",
"z",
"to",
"the",
"remainder",
"x",
"%",
"y",
".",
"See",
"QuoRem",
"for",
"more",
"details",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L959-L1009 |
5,346 | ericlagergren/decimal | big_ctx.go | RoundToInt | func (c Context) RoundToInt(z *Big) *Big {
if z.isSpecial() || z.exp >= 0 {
return z
}
c.Precision = z.Precision()
return c.Quantize(z, 0)
} | go | func (c Context) RoundToInt(z *Big) *Big {
if z.isSpecial() || z.exp >= 0 {
return z
}
c.Precision = z.Precision()
return c.Quantize(z, 0)
} | [
"func",
"(",
"c",
"Context",
")",
"RoundToInt",
"(",
"z",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"z",
".",
"isSpecial",
"(",
")",
"||",
"z",
".",
"exp",
">=",
"0",
"{",
"return",
"z",
"\n",
"}",
"\n",
"c",
".",
"Precision",
"=",
"z",
".",
... | // RoundToInt rounds z down to an integral value. | [
"RoundToInt",
"rounds",
"z",
"down",
"to",
"an",
"integral",
"value",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L1075-L1081 |
5,347 | ericlagergren/decimal | big_ctx.go | Set | func (c Context) Set(z, x *Big) *Big {
return c.Round(z.Copy(x))
} | go | func (c Context) Set(z, x *Big) *Big {
return c.Round(z.Copy(x))
} | [
"func",
"(",
"c",
"Context",
")",
"Set",
"(",
"z",
",",
"x",
"*",
"Big",
")",
"*",
"Big",
"{",
"return",
"c",
".",
"Round",
"(",
"z",
".",
"Copy",
"(",
"x",
")",
")",
"\n",
"}"
] | // Set sets z to x and returns z. The result might be rounded, even if z == x. | [
"Set",
"sets",
"z",
"to",
"x",
"and",
"returns",
"z",
".",
"The",
"result",
"might",
"be",
"rounded",
"even",
"if",
"z",
"==",
"x",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L1084-L1086 |
5,348 | ericlagergren/decimal | big_ctx.go | SetString | func (c Context) SetString(z *Big, s string) (*Big, bool) {
if _, ok := z.SetString(s); !ok {
return nil, false
}
return c.Round(z), true
} | go | func (c Context) SetString(z *Big, s string) (*Big, bool) {
if _, ok := z.SetString(s); !ok {
return nil, false
}
return c.Round(z), true
} | [
"func",
"(",
"c",
"Context",
")",
"SetString",
"(",
"z",
"*",
"Big",
",",
"s",
"string",
")",
"(",
"*",
"Big",
",",
"bool",
")",
"{",
"if",
"_",
",",
"ok",
":=",
"z",
".",
"SetString",
"(",
"s",
")",
";",
"!",
"ok",
"{",
"return",
"nil",
",... | // SetString sets z to the value of s, returning z and a bool indicating success.
// See Big.SetString for valid formats. | [
"SetString",
"sets",
"z",
"to",
"the",
"value",
"of",
"s",
"returning",
"z",
"and",
"a",
"bool",
"indicating",
"success",
".",
"See",
"Big",
".",
"SetString",
"for",
"valid",
"formats",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L1090-L1095 |
5,349 | ericlagergren/decimal | big_ctx.go | Sub | func (c Context) Sub(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
z.form = c.add(z, x, x.form, y, y.form^signbit)
return c.round(z)
}
// NaN - NaN
// NaN - y
// x - NaN
if z.checkNaNs(x, y, subtraction) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 && (x.form&signbit == y.form&signbit) {
// -Inf - -Inf
// -Inf - -Inf
return z.setNaN(InvalidOperation, qnan, subinfinf)
}
// ±Inf - y
// -Inf - +Inf
// +Inf - -Inf
return z.Set(x)
}
// x - ±Inf
return z.Neg(y)
} | go | func (c Context) Sub(z, x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
if z.invalidContext(c) {
return z
}
if x.IsFinite() && y.IsFinite() {
z.form = c.add(z, x, x.form, y, y.form^signbit)
return c.round(z)
}
// NaN - NaN
// NaN - y
// x - NaN
if z.checkNaNs(x, y, subtraction) {
return z
}
if x.form&inf != 0 {
if y.form&inf != 0 && (x.form&signbit == y.form&signbit) {
// -Inf - -Inf
// -Inf - -Inf
return z.setNaN(InvalidOperation, qnan, subinfinf)
}
// ±Inf - y
// -Inf - +Inf
// +Inf - -Inf
return z.Set(x)
}
// x - ±Inf
return z.Neg(y)
} | [
"func",
"(",
"c",
"Context",
")",
"Sub",
"(",
"z",
",",
"x",
",",
"y",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"z",
".",
"invalidCont... | // Sub sets z to x - y and returns z. | [
"Sub",
"sets",
"z",
"to",
"x",
"-",
"y",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big_ctx.go#L1098-L1132 |
5,350 | ericlagergren/decimal | misc/misc.go | CmpTotalAbs | func CmpTotalAbs(x, y *decimal.Big) int {
xs := ord(x, true)
ys := ord(y, true)
if xs != ys {
if xs > ys {
return +1
}
return -1
}
if xs != 0 {
return 0
}
return x.CmpAbs(y)
} | go | func CmpTotalAbs(x, y *decimal.Big) int {
xs := ord(x, true)
ys := ord(y, true)
if xs != ys {
if xs > ys {
return +1
}
return -1
}
if xs != 0 {
return 0
}
return x.CmpAbs(y)
} | [
"func",
"CmpTotalAbs",
"(",
"x",
",",
"y",
"*",
"decimal",
".",
"Big",
")",
"int",
"{",
"xs",
":=",
"ord",
"(",
"x",
",",
"true",
")",
"\n",
"ys",
":=",
"ord",
"(",
"y",
",",
"true",
")",
"\n",
"if",
"xs",
"!=",
"ys",
"{",
"if",
"xs",
">",
... | // CmpTotalAbs is like CmpTotal but instead compares the absolute values of x
// and y. | [
"CmpTotalAbs",
"is",
"like",
"CmpTotal",
"but",
"instead",
"compares",
"the",
"absolute",
"values",
"of",
"x",
"and",
"y",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L101-L114 |
5,351 | ericlagergren/decimal | misc/misc.go | CopyAbs | func CopyAbs(z, x *decimal.Big) *decimal.Big {
return z.CopySign(x, pos)
} | go | func CopyAbs(z, x *decimal.Big) *decimal.Big {
return z.CopySign(x, pos)
} | [
"func",
"CopyAbs",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"return",
"z",
".",
"CopySign",
"(",
"x",
",",
"pos",
")",
"\n",
"}"
] | // CopyAbs is like Abs, but no flags are changed and the result is not rounded. | [
"CopyAbs",
"is",
"like",
"Abs",
"but",
"no",
"flags",
"are",
"changed",
"and",
"the",
"result",
"is",
"not",
"rounded",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L117-L119 |
5,352 | ericlagergren/decimal | misc/misc.go | CopyNeg | func CopyNeg(z, x *decimal.Big) *decimal.Big {
if x.Signbit() {
return z.CopySign(x, pos)
}
return z.CopySign(x, neg)
} | go | func CopyNeg(z, x *decimal.Big) *decimal.Big {
if x.Signbit() {
return z.CopySign(x, pos)
}
return z.CopySign(x, neg)
} | [
"func",
"CopyNeg",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"x",
".",
"Signbit",
"(",
")",
"{",
"return",
"z",
".",
"CopySign",
"(",
"x",
",",
"pos",
")",
"\n",
"}",
"\n",
"return",
"z",
".",... | // CopyNeg is like Neg, but no flags are changed and the result is not rounded. | [
"CopyNeg",
"is",
"like",
"Neg",
"but",
"no",
"flags",
"are",
"changed",
"and",
"the",
"result",
"is",
"not",
"rounded",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L122-L127 |
5,353 | ericlagergren/decimal | misc/misc.go | Max | func Max(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.Cmp(m) > 0 {
m = v
}
}
return m
} | go | func Max(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.Cmp(m) > 0 {
m = v
}
}
return m
} | [
"func",
"Max",
"(",
"x",
"...",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"m",
":=",
"x",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"x",
"[",
"1",
":",
"]",
"{",
"if",
"v",
".",
"Cmp",
"(",
"m",
"... | // Max returns the greater of the provided values.
//
// The result is undefined if no values are are provided. | [
"Max",
"returns",
"the",
"greater",
"of",
"the",
"provided",
"values",
".",
"The",
"result",
"is",
"undefined",
"if",
"no",
"values",
"are",
"are",
"provided",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L141-L149 |
5,354 | ericlagergren/decimal | misc/misc.go | MaxAbs | func MaxAbs(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.CmpAbs(m) > 0 {
m = v
}
}
return m
} | go | func MaxAbs(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.CmpAbs(m) > 0 {
m = v
}
}
return m
} | [
"func",
"MaxAbs",
"(",
"x",
"...",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"m",
":=",
"x",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"x",
"[",
"1",
":",
"]",
"{",
"if",
"v",
".",
"CmpAbs",
"(",
"m... | // MaxAbs returns the greater of the absolute value of the provided values.
//
// The result is undefined if no values are provided. | [
"MaxAbs",
"returns",
"the",
"greater",
"of",
"the",
"absolute",
"value",
"of",
"the",
"provided",
"values",
".",
"The",
"result",
"is",
"undefined",
"if",
"no",
"values",
"are",
"provided",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L154-L162 |
5,355 | ericlagergren/decimal | misc/misc.go | Min | func Min(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.Cmp(m) < 0 {
m = v
}
}
return m
} | go | func Min(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.Cmp(m) < 0 {
m = v
}
}
return m
} | [
"func",
"Min",
"(",
"x",
"...",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"m",
":=",
"x",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"x",
"[",
"1",
":",
"]",
"{",
"if",
"v",
".",
"Cmp",
"(",
"m",
"... | // Min returns the lesser of the provided values.
//
// The result is undefined if no values are are provided. | [
"Min",
"returns",
"the",
"lesser",
"of",
"the",
"provided",
"values",
".",
"The",
"result",
"is",
"undefined",
"if",
"no",
"values",
"are",
"are",
"provided",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L167-L175 |
5,356 | ericlagergren/decimal | misc/misc.go | MinAbs | func MinAbs(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.CmpAbs(m) < 0 {
m = v
}
}
return m
} | go | func MinAbs(x ...*decimal.Big) *decimal.Big {
m := x[0]
for _, v := range x[1:] {
if v.CmpAbs(m) < 0 {
m = v
}
}
return m
} | [
"func",
"MinAbs",
"(",
"x",
"...",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"m",
":=",
"x",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"x",
"[",
"1",
":",
"]",
"{",
"if",
"v",
".",
"CmpAbs",
"(",
"m... | // MinAbs returns the lesser of the absolute value of the provided values. The
// result is undefined if no values are provided. | [
"MinAbs",
"returns",
"the",
"lesser",
"of",
"the",
"absolute",
"value",
"of",
"the",
"provided",
"values",
".",
"The",
"result",
"is",
"undefined",
"if",
"no",
"values",
"are",
"provided",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L179-L187 |
5,357 | ericlagergren/decimal | misc/misc.go | maxfor | func maxfor(z *big.Int, n, sign int) {
arith.Sub(z, arith.BigPow10(uint64(n)), 1)
if sign < 0 {
z.Neg(z)
}
} | go | func maxfor(z *big.Int, n, sign int) {
arith.Sub(z, arith.BigPow10(uint64(n)), 1)
if sign < 0 {
z.Neg(z)
}
} | [
"func",
"maxfor",
"(",
"z",
"*",
"big",
".",
"Int",
",",
"n",
",",
"sign",
"int",
")",
"{",
"arith",
".",
"Sub",
"(",
"z",
",",
"arith",
".",
"BigPow10",
"(",
"uint64",
"(",
"n",
")",
")",
",",
"1",
")",
"\n",
"if",
"sign",
"<",
"0",
"{",
... | // maxfor sets z to 999...n with the provided sign. | [
"maxfor",
"sets",
"z",
"to",
"999",
"...",
"n",
"with",
"the",
"provided",
"sign",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L190-L195 |
5,358 | ericlagergren/decimal | misc/misc.go | NextMinus | func NextMinus(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
if x.IsInf(0) {
if x.IsInf(-1) {
return z.SetInf(true)
}
_, m := decimal.Raw(z)
maxfor(m, precision(z), +1)
return z.SetBigMantScale(m, -etop(z))
}
ctx := z.Context
ctx.RoundingMode = decimal.ToNegativeInf
ctx.Set(z, x)
ctx.Sub(z, x, new(decimal.Big).SetMantScale(1, -etiny(z)+1))
z.Context.Conditions &= ctx.Conditions
return z
} | go | func NextMinus(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
if x.IsInf(0) {
if x.IsInf(-1) {
return z.SetInf(true)
}
_, m := decimal.Raw(z)
maxfor(m, precision(z), +1)
return z.SetBigMantScale(m, -etop(z))
}
ctx := z.Context
ctx.RoundingMode = decimal.ToNegativeInf
ctx.Set(z, x)
ctx.Sub(z, x, new(decimal.Big).SetMantScale(1, -etiny(z)+1))
z.Context.Conditions &= ctx.Conditions
return z
} | [
"func",
"NextMinus",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"z",
".",
"CheckNaNs",
"(",
"x",
",",
"nil",
")",
"{",
"return",
"z",
"\n",
"}",
"\n\n",
"if",
"x",
".",
"IsInf",
"(",
"0",
")",
... | // NextMinus sets z to the smallest representable number that's smaller than x
// and returns z. If x is negative infinity the result will be negative infinity.
// If the result is zero its sign will be negative and its scale will be MinScale. | [
"NextMinus",
"sets",
"z",
"to",
"the",
"smallest",
"representable",
"number",
"that",
"s",
"smaller",
"than",
"x",
"and",
"returns",
"z",
".",
"If",
"x",
"is",
"negative",
"infinity",
"the",
"result",
"will",
"be",
"negative",
"infinity",
".",
"If",
"the",... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L200-L220 |
5,359 | ericlagergren/decimal | misc/misc.go | NextPlus | func NextPlus(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
if x.IsInf(0) {
if x.IsInf(+1) {
return z.SetInf(false)
}
_, m := decimal.Raw(z)
maxfor(m, precision(z), -1)
return z.SetBigMantScale(m, -etop(z))
}
ctx := z.Context
ctx.RoundingMode = decimal.ToPositiveInf
ctx.Set(z, x)
ctx.Add(z, x, new(decimal.Big).SetMantScale(1, -etiny(z)+1))
z.Context.Conditions &= ctx.Conditions
return z
} | go | func NextPlus(z, x *decimal.Big) *decimal.Big {
if z.CheckNaNs(x, nil) {
return z
}
if x.IsInf(0) {
if x.IsInf(+1) {
return z.SetInf(false)
}
_, m := decimal.Raw(z)
maxfor(m, precision(z), -1)
return z.SetBigMantScale(m, -etop(z))
}
ctx := z.Context
ctx.RoundingMode = decimal.ToPositiveInf
ctx.Set(z, x)
ctx.Add(z, x, new(decimal.Big).SetMantScale(1, -etiny(z)+1))
z.Context.Conditions &= ctx.Conditions
return z
} | [
"func",
"NextPlus",
"(",
"z",
",",
"x",
"*",
"decimal",
".",
"Big",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"z",
".",
"CheckNaNs",
"(",
"x",
",",
"nil",
")",
"{",
"return",
"z",
"\n",
"}",
"\n\n",
"if",
"x",
".",
"IsInf",
"(",
"0",
")",
... | // NextPlus sets z to the largest representable number that's larger than x and
// returns z. If x is positive infinity the result will be positive infinity. If
// the result is zero it will be positive and its scale will be MaxScale. | [
"NextPlus",
"sets",
"z",
"to",
"the",
"largest",
"representable",
"number",
"that",
"s",
"larger",
"than",
"x",
"and",
"returns",
"z",
".",
"If",
"x",
"is",
"positive",
"infinity",
"the",
"result",
"will",
"be",
"positive",
"infinity",
".",
"If",
"the",
... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L225-L245 |
5,360 | ericlagergren/decimal | misc/misc.go | SetSignbit | func SetSignbit(z *decimal.Big, sign bool) *decimal.Big {
if sign {
return z.CopySign(z, neg)
}
return z.CopySign(z, pos)
} | go | func SetSignbit(z *decimal.Big, sign bool) *decimal.Big {
if sign {
return z.CopySign(z, neg)
}
return z.CopySign(z, pos)
} | [
"func",
"SetSignbit",
"(",
"z",
"*",
"decimal",
".",
"Big",
",",
"sign",
"bool",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"sign",
"{",
"return",
"z",
".",
"CopySign",
"(",
"z",
",",
"neg",
")",
"\n",
"}",
"\n",
"return",
"z",
".",
"CopySign",
... | // SetSignbit sets z to -z if sign is true, otherwise to +z. | [
"SetSignbit",
"sets",
"z",
"to",
"-",
"z",
"if",
"sign",
"is",
"true",
"otherwise",
"to",
"+",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/misc/misc.go#L283-L288 |
5,361 | ericlagergren/decimal | math/continued_frac.go | Wallis | func Wallis(z *decimal.Big, g Generator) *decimal.Big {
if !g.Next() {
return z
}
ws, ok := g.(Walliser)
if !ok {
ws = walliser{prec: precision(z) + 5}
}
a, a_1, b, b_1, p, eps := ws.Wallis()
t := g.Term()
a_1.SetUint64(1)
a.Copy(t.B)
b.SetUint64(1)
ctx := z.Context
if c, ok := g.(Contexter); ok {
ctx = c.Context()
}
for g.Next() && p.IsFinite() {
t = g.Term()
z.Copy(a)
ctx.FMA(a, a, t.B, ctx.Mul(a_1, a_1, t.A))
a_1.Copy(z)
z.Copy(b)
ctx.FMA(b, b, t.B, ctx.Mul(b_1, b_1, t.A))
b_1.Copy(z)
ctx.Quo(z, a, b)
if ctx.Sub(p, z, p).CmpAbs(eps) <= 0 {
break
}
p.Copy(z)
}
return z
} | go | func Wallis(z *decimal.Big, g Generator) *decimal.Big {
if !g.Next() {
return z
}
ws, ok := g.(Walliser)
if !ok {
ws = walliser{prec: precision(z) + 5}
}
a, a_1, b, b_1, p, eps := ws.Wallis()
t := g.Term()
a_1.SetUint64(1)
a.Copy(t.B)
b.SetUint64(1)
ctx := z.Context
if c, ok := g.(Contexter); ok {
ctx = c.Context()
}
for g.Next() && p.IsFinite() {
t = g.Term()
z.Copy(a)
ctx.FMA(a, a, t.B, ctx.Mul(a_1, a_1, t.A))
a_1.Copy(z)
z.Copy(b)
ctx.FMA(b, b, t.B, ctx.Mul(b_1, b_1, t.A))
b_1.Copy(z)
ctx.Quo(z, a, b)
if ctx.Sub(p, z, p).CmpAbs(eps) <= 0 {
break
}
p.Copy(z)
}
return z
} | [
"func",
"Wallis",
"(",
"z",
"*",
"decimal",
".",
"Big",
",",
"g",
"Generator",
")",
"*",
"decimal",
".",
"Big",
"{",
"if",
"!",
"g",
".",
"Next",
"(",
")",
"{",
"return",
"z",
"\n",
"}",
"\n\n",
"ws",
",",
"ok",
":=",
"g",
".",
"(",
"Walliser... | // Wallis sets z to the result of the continued fraction provided by the
// Generator and returns z. The fraction is evaluated in a top-down manner,
// using the recurrence algorithm discovered by John Wallis. For more information
// on continued fraction representations, see the Lentz function. | [
"Wallis",
"sets",
"z",
"to",
"the",
"result",
"of",
"the",
"continued",
"fraction",
"provided",
"by",
"the",
"Generator",
"and",
"returns",
"z",
".",
"The",
"fraction",
"is",
"evaluated",
"in",
"a",
"top",
"-",
"down",
"manner",
"using",
"the",
"recurrence... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/math/continued_frac.go#L69-L109 |
5,362 | ericlagergren/decimal | suite/suite.go | ParseCases | func ParseCases(r io.Reader) (cases []Case, err error) {
s := bufio.NewScanner(r)
s.Split(bufio.ScanLines)
for s.Scan() {
p := s.Bytes()
// Skip empty lines and comments.
if len(p) == 0 || p[0] == '#' {
continue
}
c, err := ParseCase(p)
if err != nil {
return nil, err
}
cases = append(cases, c)
}
return cases, s.Err()
} | go | func ParseCases(r io.Reader) (cases []Case, err error) {
s := bufio.NewScanner(r)
s.Split(bufio.ScanLines)
for s.Scan() {
p := s.Bytes()
// Skip empty lines and comments.
if len(p) == 0 || p[0] == '#' {
continue
}
c, err := ParseCase(p)
if err != nil {
return nil, err
}
cases = append(cases, c)
}
return cases, s.Err()
} | [
"func",
"ParseCases",
"(",
"r",
"io",
".",
"Reader",
")",
"(",
"cases",
"[",
"]",
"Case",
",",
"err",
"error",
")",
"{",
"s",
":=",
"bufio",
".",
"NewScanner",
"(",
"r",
")",
"\n",
"s",
".",
"Split",
"(",
"bufio",
".",
"ScanLines",
")",
"\n\n",
... | // ParseCases returns a slice of test cases in .fptest form read from r. | [
"ParseCases",
"returns",
"a",
"slice",
"of",
"test",
"cases",
"in",
".",
"fptest",
"form",
"read",
"from",
"r",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/suite/suite.go#L17-L35 |
5,363 | ericlagergren/decimal | suite/suite.go | ShortString | func (c Case) ShortString(length int) string {
return fmt.Sprintf("%s%d [%s, %s]: %s(%s) = %s %s",
c.Prefix, c.Prec, c.Trap, c.Mode, c.Op,
join(c.Inputs, ", ", length), trunc(c.Output, length), c.Excep)
} | go | func (c Case) ShortString(length int) string {
return fmt.Sprintf("%s%d [%s, %s]: %s(%s) = %s %s",
c.Prefix, c.Prec, c.Trap, c.Mode, c.Op,
join(c.Inputs, ", ", length), trunc(c.Output, length), c.Excep)
} | [
"func",
"(",
"c",
"Case",
")",
"ShortString",
"(",
"length",
"int",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"Prefix",
",",
"c",
".",
"Prec",
",",
"c",
".",
"Trap",
",",
"c",
".",
"Mode",
",",
"c",
... | // ShortString returns the same as String, except long data values are capped at
// length digits. | [
"ShortString",
"returns",
"the",
"same",
"as",
"String",
"except",
"long",
"data",
"values",
"are",
"capped",
"at",
"length",
"digits",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/suite/suite.go#L77-L81 |
5,364 | ericlagergren/decimal | suite/suite.go | IsNaN | func (i Data) IsNaN() (nan, signal bool) {
if len(i) == 1 {
return (i == "S" || i == "Q"), i == "S"
}
if i[0] == '-' {
i = i[1:]
}
return strings.EqualFold(string(i), "nan") ||
strings.EqualFold(string(i), "qnan") ||
strings.EqualFold(string(i), "snan"), i[0] == 's' || i[0] == 'S'
} | go | func (i Data) IsNaN() (nan, signal bool) {
if len(i) == 1 {
return (i == "S" || i == "Q"), i == "S"
}
if i[0] == '-' {
i = i[1:]
}
return strings.EqualFold(string(i), "nan") ||
strings.EqualFold(string(i), "qnan") ||
strings.EqualFold(string(i), "snan"), i[0] == 's' || i[0] == 'S'
} | [
"func",
"(",
"i",
"Data",
")",
"IsNaN",
"(",
")",
"(",
"nan",
",",
"signal",
"bool",
")",
"{",
"if",
"len",
"(",
"i",
")",
"==",
"1",
"{",
"return",
"(",
"i",
"==",
"\"",
"\"",
"||",
"i",
"==",
"\"",
"\"",
")",
",",
"i",
"==",
"\"",
"\"",... | // IsNaN returns two booleans indicating whether the data is a NaN value and
// whether it's signaling or not. | [
"IsNaN",
"returns",
"two",
"booleans",
"indicating",
"whether",
"the",
"data",
"is",
"a",
"NaN",
"value",
"and",
"whether",
"it",
"s",
"signaling",
"or",
"not",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/suite/suite.go#L120-L130 |
5,365 | ericlagergren/decimal | suite/suite.go | IsInf | func (i Data) IsInf() (int, bool) {
if len(i) != 4 {
return 0, false
}
if strings.EqualFold(string(i), "-Inf") {
return -1, true
}
if strings.EqualFold(string(i), "+Inf") {
return +1, true
}
return 0, false
} | go | func (i Data) IsInf() (int, bool) {
if len(i) != 4 {
return 0, false
}
if strings.EqualFold(string(i), "-Inf") {
return -1, true
}
if strings.EqualFold(string(i), "+Inf") {
return +1, true
}
return 0, false
} | [
"func",
"(",
"i",
"Data",
")",
"IsInf",
"(",
")",
"(",
"int",
",",
"bool",
")",
"{",
"if",
"len",
"(",
"i",
")",
"!=",
"4",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"strings",
".",
"EqualFold",
"(",
"string",
"(",
"i",
")",
... | // IsInf returns a boolean indicating whether the data is an Infinity and an
// int indicating the signedness of the Infinity. | [
"IsInf",
"returns",
"a",
"boolean",
"indicating",
"whether",
"the",
"data",
"is",
"an",
"Infinity",
"and",
"an",
"int",
"indicating",
"the",
"signedness",
"of",
"the",
"Infinity",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/suite/suite.go#L134-L145 |
5,366 | ericlagergren/decimal | big.go | CheckNaNs | func (z *Big) CheckNaNs(x, y *Big) bool {
return z.invalidContext(z.Context) || z.checkNaNs(x, y, 0)
} | go | func (z *Big) CheckNaNs(x, y *Big) bool {
return z.invalidContext(z.Context) || z.checkNaNs(x, y, 0)
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"CheckNaNs",
"(",
"x",
",",
"y",
"*",
"Big",
")",
"bool",
"{",
"return",
"z",
".",
"invalidContext",
"(",
"z",
".",
"Context",
")",
"||",
"z",
".",
"checkNaNs",
"(",
"x",
",",
"y",
",",
"0",
")",
"\n",
"}"
] | // CheckNaNs checks if either x or y is NaN. If so, it follows the rules of NaN
// handling set forth in the GDA specification. The second argument, y, may be
// nil. It returns true if either condition is a NaN. | [
"CheckNaNs",
"checks",
"if",
"either",
"x",
"or",
"y",
"is",
"NaN",
".",
"If",
"so",
"it",
"follows",
"the",
"rules",
"of",
"NaN",
"handling",
"set",
"forth",
"in",
"the",
"GDA",
"specification",
".",
"The",
"second",
"argument",
"y",
"may",
"be",
"nil... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L170-L172 |
5,367 | ericlagergren/decimal | big.go | Abs | func (z *Big) Abs(x *Big) *Big {
if debug {
x.validate()
}
if !z.invalidContext(z.Context) && !z.checkNaNs(x, x, absvalue) {
z.Context.round(z.copyAbs(x))
}
return z
} | go | func (z *Big) Abs(x *Big) *Big {
if debug {
x.validate()
}
if !z.invalidContext(z.Context) && !z.checkNaNs(x, x, absvalue) {
z.Context.round(z.copyAbs(x))
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"Abs",
"(",
"x",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"!",
"z",
".",
"invalidContext",
"(",
"z",
".",
"Context",
")",
"&&",
"!",
"z",... | // Abs sets z to the absolute value of x and returns z. | [
"Abs",
"sets",
"z",
"to",
"the",
"absolute",
"value",
"of",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L244-L252 |
5,368 | ericlagergren/decimal | big.go | cmp | func cmp(x, y *Big, abs bool) int {
if debug {
x.validate()
y.validate()
}
if x == y {
return 0
}
// NaN cmp x
// z cmp NaN
// NaN cmp NaN
if (x.form|y.form)&nan != 0 {
return 0
}
// Fast path: Catches non-finite forms like zero and ±Inf, possibly signed.
xs := x.ord(abs)
ys := y.ord(abs)
if xs != ys {
if xs > ys {
return +1
}
return -1
}
switch xs {
case 0, +2, -2:
return 0
default:
r := cmpabs(x, y)
if xs < 0 && !abs {
r = -r
}
return r
}
} | go | func cmp(x, y *Big, abs bool) int {
if debug {
x.validate()
y.validate()
}
if x == y {
return 0
}
// NaN cmp x
// z cmp NaN
// NaN cmp NaN
if (x.form|y.form)&nan != 0 {
return 0
}
// Fast path: Catches non-finite forms like zero and ±Inf, possibly signed.
xs := x.ord(abs)
ys := y.ord(abs)
if xs != ys {
if xs > ys {
return +1
}
return -1
}
switch xs {
case 0, +2, -2:
return 0
default:
r := cmpabs(x, y)
if xs < 0 && !abs {
r = -r
}
return r
}
} | [
"func",
"cmp",
"(",
"x",
",",
"y",
"*",
"Big",
",",
"abs",
"bool",
")",
"int",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"x",
"==",
"y",
"{",
"return",
"0",
"\n",... | // cmp is the implementation for both Cmp and CmpAbs. | [
"cmp",
"is",
"the",
"implementation",
"for",
"both",
"Cmp",
"and",
"CmpAbs",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L322-L358 |
5,369 | ericlagergren/decimal | big.go | Copy | func (z *Big) Copy(x *Big) *Big {
if debug {
x.validate()
}
if z != x {
sign := x.form & signbit
z.copyAbs(x)
z.form |= sign
}
return z
} | go | func (z *Big) Copy(x *Big) *Big {
if debug {
x.validate()
}
if z != x {
sign := x.form & signbit
z.copyAbs(x)
z.form |= sign
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"Copy",
"(",
"x",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"z",
"!=",
"x",
"{",
"sign",
":=",
"x",
".",
"form",
"&",
"signbit",
"\n",
"... | // Copy sets z to a copy of x and returns z. | [
"Copy",
"sets",
"z",
"to",
"a",
"copy",
"of",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L417-L427 |
5,370 | ericlagergren/decimal | big.go | copyAbs | func (z *Big) copyAbs(x *Big) *Big {
if z != x {
z.precision = x.Precision()
z.exp = x.exp
z.compact = x.compact
if x.IsFinite() && x.isInflated() {
z.unscaled.Set(&x.unscaled)
}
}
z.form = x.form & ^signbit
return z
} | go | func (z *Big) copyAbs(x *Big) *Big {
if z != x {
z.precision = x.Precision()
z.exp = x.exp
z.compact = x.compact
if x.IsFinite() && x.isInflated() {
z.unscaled.Set(&x.unscaled)
}
}
z.form = x.form & ^signbit
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"copyAbs",
"(",
"x",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"z",
"!=",
"x",
"{",
"z",
".",
"precision",
"=",
"x",
".",
"Precision",
"(",
")",
"\n",
"z",
".",
"exp",
"=",
"x",
".",
"exp",
"\n",
"z",
".",... | // copyAbs sets z to a copy of |x| and returns z. | [
"copyAbs",
"sets",
"z",
"to",
"a",
"copy",
"of",
"|x|",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L430-L441 |
5,371 | ericlagergren/decimal | big.go | CopySign | func (z *Big) CopySign(x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
// Pre-emptively capture signbit in case z == y.
sign := y.form & signbit
z.copyAbs(x)
z.form |= sign
return z
} | go | func (z *Big) CopySign(x, y *Big) *Big {
if debug {
x.validate()
y.validate()
}
// Pre-emptively capture signbit in case z == y.
sign := y.form & signbit
z.copyAbs(x)
z.form |= sign
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"CopySign",
"(",
"x",
",",
"y",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"y",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"// Pre-emptively capture signbit in cas... | // CopySign sets z to x with the sign of y and returns z. It accepts NaN values. | [
"CopySign",
"sets",
"z",
"to",
"x",
"with",
"the",
"sign",
"of",
"y",
"and",
"returns",
"z",
".",
"It",
"accepts",
"NaN",
"values",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L444-L454 |
5,372 | ericlagergren/decimal | big.go | Float64 | func (x *Big) Float64() (f float64, ok bool) {
if debug {
x.validate()
}
if !x.IsFinite() {
switch x.form {
case pinf, ninf:
return math.Inf(int(x.form & signbit)), true
case snan, qnan:
return math.NaN(), true
case ssnan, sqnan:
return math.Copysign(math.NaN(), -1), true
}
}
const (
maxPow10 = 22 // largest exact power of 10
maxMantissa = 1<<53 + 1 // largest exact mantissa
)
switch xc := x.compact; {
case !x.isCompact():
fallthrough
//lint:ignore ST1015 convoluted, but on purpose
default:
f, _ = strconv.ParseFloat(x.String(), 64)
ok = !math.IsInf(f, 0) && !math.IsNaN(f)
case xc == 0:
ok = true
case x.IsInt():
if xc, ok := x.Int64(); ok {
f = float64(xc)
} else if xc, ok := x.Uint64(); ok {
f = float64(xc)
}
ok = xc < maxMantissa || (xc&(xc-1)) == 0
case x.exp == 0:
f = float64(xc)
ok = xc < maxMantissa || (xc&(xc-1)) == 0
case x.exp > 0:
f = float64(x.compact) * math.Pow10(x.exp)
ok = x.compact < maxMantissa && x.exp < maxPow10
case x.exp < 0:
f = float64(x.compact) / math.Pow10(-x.exp)
ok = x.compact < maxMantissa && x.exp > -maxPow10
}
if x.form&signbit != 0 {
f = math.Copysign(f, -1)
}
return f, ok
} | go | func (x *Big) Float64() (f float64, ok bool) {
if debug {
x.validate()
}
if !x.IsFinite() {
switch x.form {
case pinf, ninf:
return math.Inf(int(x.form & signbit)), true
case snan, qnan:
return math.NaN(), true
case ssnan, sqnan:
return math.Copysign(math.NaN(), -1), true
}
}
const (
maxPow10 = 22 // largest exact power of 10
maxMantissa = 1<<53 + 1 // largest exact mantissa
)
switch xc := x.compact; {
case !x.isCompact():
fallthrough
//lint:ignore ST1015 convoluted, but on purpose
default:
f, _ = strconv.ParseFloat(x.String(), 64)
ok = !math.IsInf(f, 0) && !math.IsNaN(f)
case xc == 0:
ok = true
case x.IsInt():
if xc, ok := x.Int64(); ok {
f = float64(xc)
} else if xc, ok := x.Uint64(); ok {
f = float64(xc)
}
ok = xc < maxMantissa || (xc&(xc-1)) == 0
case x.exp == 0:
f = float64(xc)
ok = xc < maxMantissa || (xc&(xc-1)) == 0
case x.exp > 0:
f = float64(x.compact) * math.Pow10(x.exp)
ok = x.compact < maxMantissa && x.exp < maxPow10
case x.exp < 0:
f = float64(x.compact) / math.Pow10(-x.exp)
ok = x.compact < maxMantissa && x.exp > -maxPow10
}
if x.form&signbit != 0 {
f = math.Copysign(f, -1)
}
return f, ok
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Float64",
"(",
")",
"(",
"f",
"float64",
",",
"ok",
"bool",
")",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"x",
".",
"IsFinite",
"(",
")",
"{",
"switch",
"x",
... | // Float64 returns x as a float64 and a bool indicating whether x can fit into
// a float64 without truncation, overflow, or underflow. Special values are
// considered exact; however, special values that occur because the magnitude of
// x is too large to be represented as a float64 are not. | [
"Float64",
"returns",
"x",
"as",
"a",
"float64",
"and",
"a",
"bool",
"indicating",
"whether",
"x",
"can",
"fit",
"into",
"a",
"float64",
"without",
"truncation",
"overflow",
"or",
"underflow",
".",
"Special",
"values",
"are",
"considered",
"exact",
";",
"how... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L460-L511 |
5,373 | ericlagergren/decimal | big.go | Float | func (x *Big) Float(z *big.Float) *big.Float {
if debug {
x.validate()
}
if z == nil {
z = new(big.Float)
}
switch x.form {
case finite, finite | signbit:
if x.isZero() {
z.SetUint64(0)
} else {
z.SetRat(x.Rat(nil))
}
case pinf, ninf:
z.SetInf(x.form == pinf)
default: // snan, qnan, ssnan, sqnan:
z.SetUint64(0)
}
return z
} | go | func (x *Big) Float(z *big.Float) *big.Float {
if debug {
x.validate()
}
if z == nil {
z = new(big.Float)
}
switch x.form {
case finite, finite | signbit:
if x.isZero() {
z.SetUint64(0)
} else {
z.SetRat(x.Rat(nil))
}
case pinf, ninf:
z.SetInf(x.form == pinf)
default: // snan, qnan, ssnan, sqnan:
z.SetUint64(0)
}
return z
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Float",
"(",
"z",
"*",
"big",
".",
"Float",
")",
"*",
"big",
".",
"Float",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"z",
"==",
"nil",
"{",
"z",
"=",
"new",
"(",
... | // Float sets z to x and returns z. z is allowed to be nil. The result is
// undefined if z is a NaN value. | [
"Float",
"sets",
"z",
"to",
"x",
"and",
"returns",
"z",
".",
"z",
"is",
"allowed",
"to",
"be",
"nil",
".",
"The",
"result",
"is",
"undefined",
"if",
"z",
"is",
"a",
"NaN",
"value",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L515-L537 |
5,374 | ericlagergren/decimal | big.go | Int64 | func (x *Big) Int64() (int64, bool) {
if debug {
x.validate()
}
if !x.IsFinite() {
return 0, false
}
// x might be too large to fit into an int64 *now*, but rescaling x might
// shrink it enough. See issue #20.
if !x.isCompact() {
xb := x.Int(nil)
return xb.Int64(), xb.IsInt64()
}
u := x.compact
if x.exp != 0 {
var ok bool
if u, ok = scalex(u, x.exp); !ok {
return 0, false
}
}
su := int64(u)
if su >= 0 || x.Signbit() && su == -su {
if x.Signbit() {
su = -su
}
return su, true
}
return 0, false
} | go | func (x *Big) Int64() (int64, bool) {
if debug {
x.validate()
}
if !x.IsFinite() {
return 0, false
}
// x might be too large to fit into an int64 *now*, but rescaling x might
// shrink it enough. See issue #20.
if !x.isCompact() {
xb := x.Int(nil)
return xb.Int64(), xb.IsInt64()
}
u := x.compact
if x.exp != 0 {
var ok bool
if u, ok = scalex(u, x.exp); !ok {
return 0, false
}
}
su := int64(u)
if su >= 0 || x.Signbit() && su == -su {
if x.Signbit() {
su = -su
}
return su, true
}
return 0, false
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Int64",
"(",
")",
"(",
"int64",
",",
"bool",
")",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"x",
".",
"IsFinite",
"(",
")",
"{",
"return",
"0",
",",
"false",
"... | // Int64 returns x as an int64, truncating towards zero. The returned boolean
// indicates whether the conversion to an int64 was successful. | [
"Int64",
"returns",
"x",
"as",
"an",
"int64",
"truncating",
"towards",
"zero",
".",
"The",
"returned",
"boolean",
"indicates",
"whether",
"the",
"conversion",
"to",
"an",
"int64",
"was",
"successful",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L739-L770 |
5,375 | ericlagergren/decimal | big.go | Uint64 | func (x *Big) Uint64() (uint64, bool) {
if debug {
x.validate()
}
if !x.IsFinite() || x.Signbit() {
return 0, false
}
// x might be too large to fit into an uint64 *now*, but rescaling x might
// shrink it enough. See issue #20.
if !x.isCompact() {
xb := x.Int(nil)
return xb.Uint64(), xb.IsUint64()
}
b := x.compact
if x.exp == 0 {
return b, true
}
return scalex(b, x.exp)
} | go | func (x *Big) Uint64() (uint64, bool) {
if debug {
x.validate()
}
if !x.IsFinite() || x.Signbit() {
return 0, false
}
// x might be too large to fit into an uint64 *now*, but rescaling x might
// shrink it enough. See issue #20.
if !x.isCompact() {
xb := x.Int(nil)
return xb.Uint64(), xb.IsUint64()
}
b := x.compact
if x.exp == 0 {
return b, true
}
return scalex(b, x.exp)
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Uint64",
"(",
")",
"(",
"uint64",
",",
"bool",
")",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"x",
".",
"IsFinite",
"(",
")",
"||",
"x",
".",
"Signbit",
"(",
"... | // Uint64 returns x as a uint64, truncating towards zero. The returned boolean
// indicates whether the conversion to a uint64 was successful. | [
"Uint64",
"returns",
"x",
"as",
"a",
"uint64",
"truncating",
"towards",
"zero",
".",
"The",
"returned",
"boolean",
"indicates",
"whether",
"the",
"conversion",
"to",
"a",
"uint64",
"was",
"successful",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L774-L795 |
5,376 | ericlagergren/decimal | big.go | IsNormal | func (x *Big) IsNormal() bool {
return x.IsFinite() && x.adjusted() >= x.Context.minScale()
} | go | func (x *Big) IsNormal() bool {
return x.IsFinite() && x.adjusted() >= x.Context.minScale()
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"IsNormal",
"(",
")",
"bool",
"{",
"return",
"x",
".",
"IsFinite",
"(",
")",
"&&",
"x",
".",
"adjusted",
"(",
")",
">=",
"x",
".",
"Context",
".",
"minScale",
"(",
")",
"\n",
"}"
] | // IsNormal returns true if x is normal. | [
"IsNormal",
"returns",
"true",
"if",
"x",
"is",
"normal",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L801-L803 |
5,377 | ericlagergren/decimal | big.go | IsSubnormal | func (x *Big) IsSubnormal() bool {
return x.IsFinite() && x.adjusted() < x.Context.minScale()
} | go | func (x *Big) IsSubnormal() bool {
return x.IsFinite() && x.adjusted() < x.Context.minScale()
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"IsSubnormal",
"(",
")",
"bool",
"{",
"return",
"x",
".",
"IsFinite",
"(",
")",
"&&",
"x",
".",
"adjusted",
"(",
")",
"<",
"x",
".",
"Context",
".",
"minScale",
"(",
")",
"\n",
"}"
] | // IsSubnormal returns true if x is subnormal. | [
"IsSubnormal",
"returns",
"true",
"if",
"x",
"is",
"subnormal",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L806-L808 |
5,378 | ericlagergren/decimal | big.go | IsInt | func (x *Big) IsInt() bool {
if debug {
x.validate()
}
if !x.IsFinite() {
return false
}
// 0, 5000, 40
if x.isZero() || x.exp >= 0 {
return true
}
xp := x.Precision()
exp := x.exp
// 0.001
// 0.5
if -exp >= xp {
return false
}
// 44.00
// 1.000
if x.isCompact() {
for v := x.compact; v%10 == 0; v /= 10 {
exp++
}
// Avoid the overhead of copying x.unscaled if we know for a fact it's not
// an integer.
} else if x.unscaled.Bit(0) == 0 {
v := new(big.Int).Set(&x.unscaled)
r := new(big.Int)
for {
v.QuoRem(v, c.TenInt, r)
if r.Sign() != 0 {
break
}
exp++
}
}
return exp >= 0
} | go | func (x *Big) IsInt() bool {
if debug {
x.validate()
}
if !x.IsFinite() {
return false
}
// 0, 5000, 40
if x.isZero() || x.exp >= 0 {
return true
}
xp := x.Precision()
exp := x.exp
// 0.001
// 0.5
if -exp >= xp {
return false
}
// 44.00
// 1.000
if x.isCompact() {
for v := x.compact; v%10 == 0; v /= 10 {
exp++
}
// Avoid the overhead of copying x.unscaled if we know for a fact it's not
// an integer.
} else if x.unscaled.Bit(0) == 0 {
v := new(big.Int).Set(&x.unscaled)
r := new(big.Int)
for {
v.QuoRem(v, c.TenInt, r)
if r.Sign() != 0 {
break
}
exp++
}
}
return exp >= 0
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"IsInt",
"(",
")",
"bool",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"x",
".",
"IsFinite",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"// 0, 5000, 40",
"i... | // IsInt reports whether x is an integer. Infinity and NaN values are not
// integers. | [
"IsInt",
"reports",
"whether",
"x",
"is",
"an",
"integer",
".",
"Infinity",
"and",
"NaN",
"values",
"are",
"not",
"integers",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L828-L871 |
5,379 | ericlagergren/decimal | big.go | Neg | func (z *Big) Neg(x *Big) *Big {
if debug {
x.validate()
}
if !z.invalidContext(z.Context) && !z.checkNaNs(x, x, negation) {
xform := x.form // copy in case z == x
z.copyAbs(x)
if !z.IsFinite() || z.compact != 0 || z.Context.RoundingMode == ToNegativeInf {
z.form = xform ^ signbit
}
}
return z.Context.round(z)
} | go | func (z *Big) Neg(x *Big) *Big {
if debug {
x.validate()
}
if !z.invalidContext(z.Context) && !z.checkNaNs(x, x, negation) {
xform := x.form // copy in case z == x
z.copyAbs(x)
if !z.IsFinite() || z.compact != 0 || z.Context.RoundingMode == ToNegativeInf {
z.form = xform ^ signbit
}
}
return z.Context.round(z)
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"Neg",
"(",
"x",
"*",
"Big",
")",
"*",
"Big",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"if",
"!",
"z",
".",
"invalidContext",
"(",
"z",
".",
"Context",
")",
"&&",
"!",
"z",... | // Neg sets z to -x and returns z. If x is positive infinity, z will be set to
// negative infinity and visa versa. If x == 0, z will be set to zero as well.
// NaN will result in an error. | [
"Neg",
"sets",
"z",
"to",
"-",
"x",
"and",
"returns",
"z",
".",
"If",
"x",
"is",
"positive",
"infinity",
"z",
"will",
"be",
"set",
"to",
"negative",
"infinity",
"and",
"visa",
"versa",
".",
"If",
"x",
"==",
"0",
"z",
"will",
"be",
"set",
"to",
"z... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L897-L909 |
5,380 | ericlagergren/decimal | big.go | Precision | func (x *Big) Precision() int {
// Cannot call validate since validate calls this method.
if !x.IsFinite() {
return 0
}
if x.precision == 0 {
return 1
}
return x.precision
} | go | func (x *Big) Precision() int {
// Cannot call validate since validate calls this method.
if !x.IsFinite() {
return 0
}
if x.precision == 0 {
return 1
}
return x.precision
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Precision",
"(",
")",
"int",
"{",
"// Cannot call validate since validate calls this method.",
"if",
"!",
"x",
".",
"IsFinite",
"(",
")",
"{",
"return",
"0",
"\n",
"}",
"\n",
"if",
"x",
".",
"precision",
"==",
"0",
"{"... | // Precision returns the precision of x. That is, it returns the number of
// digits in the unscaled form of x. x == 0 has a precision of 1. The result is
// undefined if x is not finite. | [
"Precision",
"returns",
"the",
"precision",
"of",
"x",
".",
"That",
"is",
"it",
"returns",
"the",
"number",
"of",
"digits",
"in",
"the",
"unscaled",
"form",
"of",
"x",
".",
"x",
"==",
"0",
"has",
"a",
"precision",
"of",
"1",
".",
"The",
"result",
"is... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L935-L944 |
5,381 | ericlagergren/decimal | big.go | Rat | func (x *Big) Rat(z *big.Rat) *big.Rat {
if debug {
x.validate()
}
if z == nil {
z = new(big.Rat)
}
if !x.IsFinite() {
return z.SetInt64(0)
}
// Fast path for decimals <= math.MaxInt64.
if x.IsInt() {
if u, ok := x.Int64(); ok {
// If profiled we can call scalex ourselves and save the overhead of
// calling Int64. But I doubt it'll matter much.
return z.SetInt64(u)
}
}
num := new(big.Int)
if x.isCompact() {
num.SetUint64(x.compact)
} else {
num.Set(&x.unscaled)
}
if x.exp > 0 {
arith.MulBigPow10(num, num, uint64(x.exp))
}
if x.Signbit() {
num.Neg(num)
}
denom := c.OneInt
if x.exp < 0 {
denom = new(big.Int)
if shift, ok := arith.Pow10(uint64(-x.exp)); ok {
denom.SetUint64(shift)
} else {
denom.Set(arith.BigPow10(uint64(-x.exp)))
}
}
return z.SetFrac(num, denom)
} | go | func (x *Big) Rat(z *big.Rat) *big.Rat {
if debug {
x.validate()
}
if z == nil {
z = new(big.Rat)
}
if !x.IsFinite() {
return z.SetInt64(0)
}
// Fast path for decimals <= math.MaxInt64.
if x.IsInt() {
if u, ok := x.Int64(); ok {
// If profiled we can call scalex ourselves and save the overhead of
// calling Int64. But I doubt it'll matter much.
return z.SetInt64(u)
}
}
num := new(big.Int)
if x.isCompact() {
num.SetUint64(x.compact)
} else {
num.Set(&x.unscaled)
}
if x.exp > 0 {
arith.MulBigPow10(num, num, uint64(x.exp))
}
if x.Signbit() {
num.Neg(num)
}
denom := c.OneInt
if x.exp < 0 {
denom = new(big.Int)
if shift, ok := arith.Pow10(uint64(-x.exp)); ok {
denom.SetUint64(shift)
} else {
denom.Set(arith.BigPow10(uint64(-x.exp)))
}
}
return z.SetFrac(num, denom)
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Rat",
"(",
"z",
"*",
"big",
".",
"Rat",
")",
"*",
"big",
".",
"Rat",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n\n",
"if",
"z",
"==",
"nil",
"{",
"z",
"=",
"new",
"(",
"big",... | // Rat sets z to x and returns z. z is allowed to be nil. The result is undefined if
// x is an infinity or NaN value. | [
"Rat",
"sets",
"z",
"to",
"x",
"and",
"returns",
"z",
".",
"z",
"is",
"allowed",
"to",
"be",
"nil",
".",
"The",
"result",
"is",
"undefined",
"if",
"x",
"is",
"an",
"infinity",
"or",
"NaN",
"value",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L966-L1011 |
5,382 | ericlagergren/decimal | big.go | Scan | func (z *Big) Scan(state fmt.ScanState, verb rune) error {
return z.scan(byteReader{state})
} | go | func (z *Big) Scan(state fmt.ScanState, verb rune) error {
return z.scan(byteReader{state})
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"Scan",
"(",
"state",
"fmt",
".",
"ScanState",
",",
"verb",
"rune",
")",
"error",
"{",
"return",
"z",
".",
"scan",
"(",
"byteReader",
"{",
"state",
"}",
")",
"\n",
"}"
] | // Scan implements fmt.Scanner. | [
"Scan",
"implements",
"fmt",
".",
"Scanner",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1044-L1046 |
5,383 | ericlagergren/decimal | big.go | SetBigMantScale | func (z *Big) SetBigMantScale(value *big.Int, scale int) *Big {
// Do this first in case value == z.unscaled. Don't want to clobber the sign.
z.form = finite
if value.Sign() < 0 {
z.form |= signbit
}
z.unscaled.Abs(value)
z.compact = c.Inflated
z.precision = arith.BigLength(value)
if z.unscaled.IsUint64() {
if v := z.unscaled.Uint64(); v != c.Inflated {
z.compact = v
}
}
z.exp = -scale
return z
} | go | func (z *Big) SetBigMantScale(value *big.Int, scale int) *Big {
// Do this first in case value == z.unscaled. Don't want to clobber the sign.
z.form = finite
if value.Sign() < 0 {
z.form |= signbit
}
z.unscaled.Abs(value)
z.compact = c.Inflated
z.precision = arith.BigLength(value)
if z.unscaled.IsUint64() {
if v := z.unscaled.Uint64(); v != c.Inflated {
z.compact = v
}
}
z.exp = -scale
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetBigMantScale",
"(",
"value",
"*",
"big",
".",
"Int",
",",
"scale",
"int",
")",
"*",
"Big",
"{",
"// Do this first in case value == z.unscaled. Don't want to clobber the sign.",
"z",
".",
"form",
"=",
"finite",
"\n",
"if",
... | // SetBigMantScale sets z to the given value and scale. | [
"SetBigMantScale",
"sets",
"z",
"to",
"the",
"given",
"value",
"and",
"scale",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1069-L1088 |
5,384 | ericlagergren/decimal | big.go | SetFloat | func (z *Big) SetFloat(x *big.Float) *Big {
if x.IsInf() {
if x.Signbit() {
z.form = ninf
} else {
z.form = pinf
}
return z
}
neg := x.Signbit()
if x.Sign() == 0 {
if neg {
z.form |= signbit
}
z.compact = 0
z.precision = 1
return z
}
z.exp = 0
x0 := new(big.Float).Copy(x).SetPrec(big.MaxPrec)
x0.Abs(x0)
if !x.IsInt() {
for !x0.IsInt() {
x0.Mul(x0, c.TenFloat)
z.exp--
}
}
if mant, acc := x0.Uint64(); acc == big.Exact {
z.compact = mant
z.precision = arith.Length(mant)
} else {
z.compact = c.Inflated
x0.Int(&z.unscaled)
z.precision = arith.BigLength(&z.unscaled)
}
z.form = finite
if neg {
z.form |= signbit
}
return z
} | go | func (z *Big) SetFloat(x *big.Float) *Big {
if x.IsInf() {
if x.Signbit() {
z.form = ninf
} else {
z.form = pinf
}
return z
}
neg := x.Signbit()
if x.Sign() == 0 {
if neg {
z.form |= signbit
}
z.compact = 0
z.precision = 1
return z
}
z.exp = 0
x0 := new(big.Float).Copy(x).SetPrec(big.MaxPrec)
x0.Abs(x0)
if !x.IsInt() {
for !x0.IsInt() {
x0.Mul(x0, c.TenFloat)
z.exp--
}
}
if mant, acc := x0.Uint64(); acc == big.Exact {
z.compact = mant
z.precision = arith.Length(mant)
} else {
z.compact = c.Inflated
x0.Int(&z.unscaled)
z.precision = arith.BigLength(&z.unscaled)
}
z.form = finite
if neg {
z.form |= signbit
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetFloat",
"(",
"x",
"*",
"big",
".",
"Float",
")",
"*",
"Big",
"{",
"if",
"x",
".",
"IsInf",
"(",
")",
"{",
"if",
"x",
".",
"Signbit",
"(",
")",
"{",
"z",
".",
"form",
"=",
"ninf",
"\n",
"}",
"else",
"... | // SetFloat sets z to exactly x and returns z. | [
"SetFloat",
"sets",
"z",
"to",
"exactly",
"x",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1091-L1134 |
5,385 | ericlagergren/decimal | big.go | SetFloat64 | func (z *Big) SetFloat64(x float64) *Big {
if x == 0 {
var sign form
if math.Signbit(x) {
sign = signbit
}
return z.setZero(sign, 0)
}
if math.IsNaN(x) {
var sign form
if math.Signbit(x) {
sign = signbit
}
return z.setNaN(0, qnan|sign, 0)
}
if math.IsInf(x, 0) {
if math.IsInf(x, 1) {
z.form = pinf
} else {
z.form = ninf
}
return z
}
// The gist of the following is lifted from math/big/rat.go, but adapted for
// base-10 decimals.
const expMask = 1<<11 - 1
bits := math.Float64bits(x)
mantissa := bits & (1<<52 - 1)
exp := int((bits >> 52) & expMask)
if exp == 0 { // denormal
exp -= 1022
} else { // normal
mantissa |= 1 << 52
exp -= 1023
}
if mantissa == 0 {
return z.SetUint64(0)
}
shift := 52 - exp
for mantissa&1 == 0 && shift > 0 {
mantissa >>= 1
shift--
}
z.exp = 0
z.form = finite | form(bits>>63)
if shift > 0 {
z.unscaled.SetUint64(uint64(shift))
z.unscaled.Exp(c.FiveInt, &z.unscaled, nil)
arith.Mul(&z.unscaled, &z.unscaled, mantissa)
z.exp = -shift
} else {
// TODO(eric): figure out why this doesn't work for _some_ numbers. See
// https://github.com/ericlagergren/decimal/issues/89
//
// z.compact = mantissa << uint(-shift)
// z.precision = arith.Length(z.compact)
z.compact = c.Inflated
z.unscaled.SetUint64(mantissa)
z.unscaled.Lsh(&z.unscaled, uint(-shift))
}
return z.norm()
} | go | func (z *Big) SetFloat64(x float64) *Big {
if x == 0 {
var sign form
if math.Signbit(x) {
sign = signbit
}
return z.setZero(sign, 0)
}
if math.IsNaN(x) {
var sign form
if math.Signbit(x) {
sign = signbit
}
return z.setNaN(0, qnan|sign, 0)
}
if math.IsInf(x, 0) {
if math.IsInf(x, 1) {
z.form = pinf
} else {
z.form = ninf
}
return z
}
// The gist of the following is lifted from math/big/rat.go, but adapted for
// base-10 decimals.
const expMask = 1<<11 - 1
bits := math.Float64bits(x)
mantissa := bits & (1<<52 - 1)
exp := int((bits >> 52) & expMask)
if exp == 0 { // denormal
exp -= 1022
} else { // normal
mantissa |= 1 << 52
exp -= 1023
}
if mantissa == 0 {
return z.SetUint64(0)
}
shift := 52 - exp
for mantissa&1 == 0 && shift > 0 {
mantissa >>= 1
shift--
}
z.exp = 0
z.form = finite | form(bits>>63)
if shift > 0 {
z.unscaled.SetUint64(uint64(shift))
z.unscaled.Exp(c.FiveInt, &z.unscaled, nil)
arith.Mul(&z.unscaled, &z.unscaled, mantissa)
z.exp = -shift
} else {
// TODO(eric): figure out why this doesn't work for _some_ numbers. See
// https://github.com/ericlagergren/decimal/issues/89
//
// z.compact = mantissa << uint(-shift)
// z.precision = arith.Length(z.compact)
z.compact = c.Inflated
z.unscaled.SetUint64(mantissa)
z.unscaled.Lsh(&z.unscaled, uint(-shift))
}
return z.norm()
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetFloat64",
"(",
"x",
"float64",
")",
"*",
"Big",
"{",
"if",
"x",
"==",
"0",
"{",
"var",
"sign",
"form",
"\n",
"if",
"math",
".",
"Signbit",
"(",
"x",
")",
"{",
"sign",
"=",
"signbit",
"\n",
"}",
"\n",
"re... | // SetFloat64 sets z to exactly x. | [
"SetFloat64",
"sets",
"z",
"to",
"exactly",
"x",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1137-L1205 |
5,386 | ericlagergren/decimal | big.go | SetInf | func (z *Big) SetInf(signbit bool) *Big {
if signbit {
z.form = ninf
} else {
z.form = pinf
}
return z
} | go | func (z *Big) SetInf(signbit bool) *Big {
if signbit {
z.form = ninf
} else {
z.form = pinf
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetInf",
"(",
"signbit",
"bool",
")",
"*",
"Big",
"{",
"if",
"signbit",
"{",
"z",
".",
"form",
"=",
"ninf",
"\n",
"}",
"else",
"{",
"z",
".",
"form",
"=",
"pinf",
"\n",
"}",
"\n",
"return",
"z",
"\n",
"}"
] | // SetInf sets z to -Inf if signbit is set or +Inf is signbit is not set, and
// returns z. | [
"SetInf",
"sets",
"z",
"to",
"-",
"Inf",
"if",
"signbit",
"is",
"set",
"or",
"+",
"Inf",
"is",
"signbit",
"is",
"not",
"set",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1209-L1216 |
5,387 | ericlagergren/decimal | big.go | SetMantScale | func (z *Big) SetMantScale(value int64, scale int) *Big {
z.SetUint64(arith.Abs(value))
z.exp = -scale // compiler should optimize out z.exp = 0 in SetUint64
if value < 0 {
z.form |= signbit
}
return z
} | go | func (z *Big) SetMantScale(value int64, scale int) *Big {
z.SetUint64(arith.Abs(value))
z.exp = -scale // compiler should optimize out z.exp = 0 in SetUint64
if value < 0 {
z.form |= signbit
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetMantScale",
"(",
"value",
"int64",
",",
"scale",
"int",
")",
"*",
"Big",
"{",
"z",
".",
"SetUint64",
"(",
"arith",
".",
"Abs",
"(",
"value",
")",
")",
"\n",
"z",
".",
"exp",
"=",
"-",
"scale",
"// compiler s... | // SetMantScale sets z to the given value and scale. | [
"SetMantScale",
"sets",
"z",
"to",
"the",
"given",
"value",
"and",
"scale",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1219-L1226 |
5,388 | ericlagergren/decimal | big.go | setNaN | func (z *Big) setNaN(c Condition, f form, p Payload) *Big {
z.form = f
z.compact = uint64(p)
z.Context.Conditions |= c
if z.Context.OperatingMode == Go {
panic(ErrNaN{Msg: z.Context.Conditions.String()})
}
return z
} | go | func (z *Big) setNaN(c Condition, f form, p Payload) *Big {
z.form = f
z.compact = uint64(p)
z.Context.Conditions |= c
if z.Context.OperatingMode == Go {
panic(ErrNaN{Msg: z.Context.Conditions.String()})
}
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"setNaN",
"(",
"c",
"Condition",
",",
"f",
"form",
",",
"p",
"Payload",
")",
"*",
"Big",
"{",
"z",
".",
"form",
"=",
"f",
"\n",
"z",
".",
"compact",
"=",
"uint64",
"(",
"p",
")",
"\n",
"z",
".",
"Context",
... | // setNaN is an internal NaN-setting method that panics when the OperatingMode
// is Go. | [
"setNaN",
"is",
"an",
"internal",
"NaN",
"-",
"setting",
"method",
"that",
"panics",
"when",
"the",
"OperatingMode",
"is",
"Go",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1230-L1238 |
5,389 | ericlagergren/decimal | big.go | SetNaN | func (z *Big) SetNaN(signal bool) *Big {
if signal {
z.form = snan
} else {
z.form = qnan
}
z.compact = 0 // payload
return z
} | go | func (z *Big) SetNaN(signal bool) *Big {
if signal {
z.form = snan
} else {
z.form = qnan
}
z.compact = 0 // payload
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetNaN",
"(",
"signal",
"bool",
")",
"*",
"Big",
"{",
"if",
"signal",
"{",
"z",
".",
"form",
"=",
"snan",
"\n",
"}",
"else",
"{",
"z",
".",
"form",
"=",
"qnan",
"\n",
"}",
"\n",
"z",
".",
"compact",
"=",
... | // SetNaN sets z to a signaling NaN if signal is true or quiet NaN otherwise and
// returns z. No conditions are raised. | [
"SetNaN",
"sets",
"z",
"to",
"a",
"signaling",
"NaN",
"if",
"signal",
"is",
"true",
"or",
"quiet",
"NaN",
"otherwise",
"and",
"returns",
"z",
".",
"No",
"conditions",
"are",
"raised",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1242-L1250 |
5,390 | ericlagergren/decimal | big.go | SetRat | func (z *Big) SetRat(x *big.Rat) *Big {
if x.IsInt() {
return z.Context.round(z.SetBigMantScale(x.Num(), 0))
}
var num, denom Big
num.SetBigMantScale(x.Num(), 0)
denom.SetBigMantScale(x.Denom(), 0)
return z.Quo(&num, &denom)
} | go | func (z *Big) SetRat(x *big.Rat) *Big {
if x.IsInt() {
return z.Context.round(z.SetBigMantScale(x.Num(), 0))
}
var num, denom Big
num.SetBigMantScale(x.Num(), 0)
denom.SetBigMantScale(x.Denom(), 0)
return z.Quo(&num, &denom)
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetRat",
"(",
"x",
"*",
"big",
".",
"Rat",
")",
"*",
"Big",
"{",
"if",
"x",
".",
"IsInt",
"(",
")",
"{",
"return",
"z",
".",
"Context",
".",
"round",
"(",
"z",
".",
"SetBigMantScale",
"(",
"x",
".",
"Num",
... | // SetRat sets z to to the possibly rounded value of x and return z. | [
"SetRat",
"sets",
"z",
"to",
"to",
"the",
"possibly",
"rounded",
"value",
"of",
"x",
"and",
"return",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1253-L1261 |
5,391 | ericlagergren/decimal | big.go | SetScale | func (z *Big) SetScale(scale int) *Big {
z.exp = -scale
return z
} | go | func (z *Big) SetScale(scale int) *Big {
z.exp = -scale
return z
} | [
"func",
"(",
"z",
"*",
"Big",
")",
"SetScale",
"(",
"scale",
"int",
")",
"*",
"Big",
"{",
"z",
".",
"exp",
"=",
"-",
"scale",
"\n",
"return",
"z",
"\n",
"}"
] | // SetScale sets z's scale to scale and returns z. | [
"SetScale",
"sets",
"z",
"s",
"scale",
"to",
"scale",
"and",
"returns",
"z",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1264-L1267 |
5,392 | ericlagergren/decimal | big.go | ord | func (x *Big) ord(abs bool) int {
if x.form&inf != 0 {
if x.form == pinf || abs {
return +2
}
return -2
}
r := x.Sign()
if abs && r < 0 {
r = -r
}
return r
} | go | func (x *Big) ord(abs bool) int {
if x.form&inf != 0 {
if x.form == pinf || abs {
return +2
}
return -2
}
r := x.Sign()
if abs && r < 0 {
r = -r
}
return r
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"ord",
"(",
"abs",
"bool",
")",
"int",
"{",
"if",
"x",
".",
"form",
"&",
"inf",
"!=",
"0",
"{",
"if",
"x",
".",
"form",
"==",
"pinf",
"||",
"abs",
"{",
"return",
"+",
"2",
"\n",
"}",
"\n",
"return",
"-",
... | // ord returns similar to Sign except -Inf is -2 and +Inf is +2. | [
"ord",
"returns",
"similar",
"to",
"Sign",
"except",
"-",
"Inf",
"is",
"-",
"2",
"and",
"+",
"Inf",
"is",
"+",
"2",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1327-L1339 |
5,393 | ericlagergren/decimal | big.go | Signbit | func (x *Big) Signbit() bool {
if debug {
x.validate()
}
return x.form&signbit != 0
} | go | func (x *Big) Signbit() bool {
if debug {
x.validate()
}
return x.form&signbit != 0
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"Signbit",
"(",
")",
"bool",
"{",
"if",
"debug",
"{",
"x",
".",
"validate",
"(",
")",
"\n",
"}",
"\n",
"return",
"x",
".",
"form",
"&",
"signbit",
"!=",
"0",
"\n",
"}"
] | // Signbit reports whether x is negative, negative zero, negative infinity, or
// negative NaN. | [
"Signbit",
"reports",
"whether",
"x",
"is",
"negative",
"negative",
"zero",
"negative",
"infinity",
"or",
"negative",
"NaN",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1365-L1370 |
5,394 | ericlagergren/decimal | big.go | String | func (x *Big) String() string {
if x == nil {
return "<nil>"
}
var (
b = new(strings.Builder)
f = formatter{w: b, prec: x.Precision(), width: noWidth}
e = sciE[x.Context.OperatingMode]
)
b.Grow(x.Precision())
f.format(x, normal, e)
return b.String()
} | go | func (x *Big) String() string {
if x == nil {
return "<nil>"
}
var (
b = new(strings.Builder)
f = formatter{w: b, prec: x.Precision(), width: noWidth}
e = sciE[x.Context.OperatingMode]
)
b.Grow(x.Precision())
f.format(x, normal, e)
return b.String()
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"String",
"(",
")",
"string",
"{",
"if",
"x",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"var",
"(",
"b",
"=",
"new",
"(",
"strings",
".",
"Builder",
")",
"\n",
"f",
"=",
"formatter",
"{",
"w",... | // String returns the string representation of x. It's equivalent to the %s verb
// discussed in the Format method's documentation. Special cases depend on the
// OperatingMode. | [
"String",
"returns",
"the",
"string",
"representation",
"of",
"x",
".",
"It",
"s",
"equivalent",
"to",
"the",
"%s",
"verb",
"discussed",
"in",
"the",
"Format",
"method",
"s",
"documentation",
".",
"Special",
"cases",
"depend",
"on",
"the",
"OperatingMode",
"... | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1375-L1387 |
5,395 | ericlagergren/decimal | big.go | validate | func (x *Big) validate() {
defer func() {
if err := recover(); err != nil {
pc, _, _, ok := runtime.Caller(4)
if caller := runtime.FuncForPC(pc); ok && caller != nil {
fmt.Println("called by:", caller.Name())
}
type Big struct {
Context Context
unscaled big.Int
compact uint64
exp int
precision int
form form
}
fmt.Printf("%#v\n", (*Big)(x))
panic(err)
}
}()
switch x.form {
case finite, finite | signbit:
if x.isInflated() {
if x.unscaled.IsUint64() && x.unscaled.Uint64() != c.Inflated {
panic(fmt.Sprintf("inflated but unscaled == %d", x.unscaled.Uint64()))
}
if x.unscaled.Sign() < 0 {
panic("x.unscaled.Sign() < 0")
}
if bl, xp := arith.BigLength(&x.unscaled), x.precision; bl != xp {
panic(fmt.Sprintf("BigLength (%d) != x.Precision (%d)", bl, xp))
}
}
if x.isCompact() {
if bl, xp := arith.Length(x.compact), x.Precision(); bl != xp {
panic(fmt.Sprintf("BigLength (%d) != x.Precision() (%d)", bl, xp))
}
}
case snan, ssnan, qnan, sqnan, pinf, ninf:
// OK
case nan:
panic(x.form.String())
default:
panic(fmt.Sprintf("invalid form %s", x.form))
}
} | go | func (x *Big) validate() {
defer func() {
if err := recover(); err != nil {
pc, _, _, ok := runtime.Caller(4)
if caller := runtime.FuncForPC(pc); ok && caller != nil {
fmt.Println("called by:", caller.Name())
}
type Big struct {
Context Context
unscaled big.Int
compact uint64
exp int
precision int
form form
}
fmt.Printf("%#v\n", (*Big)(x))
panic(err)
}
}()
switch x.form {
case finite, finite | signbit:
if x.isInflated() {
if x.unscaled.IsUint64() && x.unscaled.Uint64() != c.Inflated {
panic(fmt.Sprintf("inflated but unscaled == %d", x.unscaled.Uint64()))
}
if x.unscaled.Sign() < 0 {
panic("x.unscaled.Sign() < 0")
}
if bl, xp := arith.BigLength(&x.unscaled), x.precision; bl != xp {
panic(fmt.Sprintf("BigLength (%d) != x.Precision (%d)", bl, xp))
}
}
if x.isCompact() {
if bl, xp := arith.Length(x.compact), x.Precision(); bl != xp {
panic(fmt.Sprintf("BigLength (%d) != x.Precision() (%d)", bl, xp))
}
}
case snan, ssnan, qnan, sqnan, pinf, ninf:
// OK
case nan:
panic(x.form.String())
default:
panic(fmt.Sprintf("invalid form %s", x.form))
}
} | [
"func",
"(",
"x",
"*",
"Big",
")",
"validate",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
":=",
"recover",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"pc",
",",
"_",
",",
"_",
",",
"ok",
":=",
"runtime",
".",
"Caller",
"(",
"4... | // validate ensures x's internal state is correct. There's no need for it to
// have good performance since it's for debug == true only. | [
"validate",
"ensures",
"x",
"s",
"internal",
"state",
"is",
"correct",
".",
"There",
"s",
"no",
"need",
"for",
"it",
"to",
"have",
"good",
"performance",
"since",
"it",
"s",
"for",
"debug",
"==",
"true",
"only",
"."
] | 6335edbaa640ad489e084816737f93ac4a1a7595 | https://github.com/ericlagergren/decimal/blob/6335edbaa640ad489e084816737f93ac4a1a7595/big.go#L1407-L1451 |
5,396 | Pallinder/go-randomdata | postalcodes.go | Digits | func Digits(digits int) string {
max := int(math.Pow10(digits)) - 1
num := privateRand.Intn(max)
format := fmt.Sprintf("%%0%dd", digits)
return fmt.Sprintf(format, num)
} | go | func Digits(digits int) string {
max := int(math.Pow10(digits)) - 1
num := privateRand.Intn(max)
format := fmt.Sprintf("%%0%dd", digits)
return fmt.Sprintf(format, num)
} | [
"func",
"Digits",
"(",
"digits",
"int",
")",
"string",
"{",
"max",
":=",
"int",
"(",
"math",
".",
"Pow10",
"(",
"digits",
")",
")",
"-",
"1",
"\n",
"num",
":=",
"privateRand",
".",
"Intn",
"(",
"max",
")",
"\n",
"format",
":=",
"fmt",
".",
"Sprin... | // Digits generates a string of N random digits, padded with zeros if necessary. | [
"Digits",
"generates",
"a",
"string",
"of",
"N",
"random",
"digits",
"padded",
"with",
"zeros",
"if",
"necessary",
"."
] | 97a2356fcab20708fb8ae46cbbf69a5bc9feca63 | https://github.com/Pallinder/go-randomdata/blob/97a2356fcab20708fb8ae46cbbf69a5bc9feca63/postalcodes.go#L221-L226 |
5,397 | Pallinder/go-randomdata | postalcodes.go | BoundedDigits | func BoundedDigits(digits, low, high int) string {
if low > high {
low, high = high, low
}
max := int(math.Pow10(digits)) - 1
if high > max {
high = max
}
num := privateRand.Intn(high-low+1) + low
format := fmt.Sprintf("%%0%dd", digits)
return fmt.Sprintf(format, num)
} | go | func BoundedDigits(digits, low, high int) string {
if low > high {
low, high = high, low
}
max := int(math.Pow10(digits)) - 1
if high > max {
high = max
}
num := privateRand.Intn(high-low+1) + low
format := fmt.Sprintf("%%0%dd", digits)
return fmt.Sprintf(format, num)
} | [
"func",
"BoundedDigits",
"(",
"digits",
",",
"low",
",",
"high",
"int",
")",
"string",
"{",
"if",
"low",
">",
"high",
"{",
"low",
",",
"high",
"=",
"high",
",",
"low",
"\n",
"}",
"\n\n",
"max",
":=",
"int",
"(",
"math",
".",
"Pow10",
"(",
"digits... | // BoundedDigits generates a string of N random digits, padded with zeros if necessary.
// The output is restricted to the given range. | [
"BoundedDigits",
"generates",
"a",
"string",
"of",
"N",
"random",
"digits",
"padded",
"with",
"zeros",
"if",
"necessary",
".",
"The",
"output",
"is",
"restricted",
"to",
"the",
"given",
"range",
"."
] | 97a2356fcab20708fb8ae46cbbf69a5bc9feca63 | https://github.com/Pallinder/go-randomdata/blob/97a2356fcab20708fb8ae46cbbf69a5bc9feca63/postalcodes.go#L230-L243 |
5,398 | Pallinder/go-randomdata | random_data.go | Title | func Title(gender int) string {
var title = ""
switch gender {
case Male:
title = randomFrom(jsonData.MaleTitles)
break
case Female:
title = randomFrom(jsonData.FemaleTitles)
break
default:
title = FirstName(privateRand.Intn(2))
break
}
return title
} | go | func Title(gender int) string {
var title = ""
switch gender {
case Male:
title = randomFrom(jsonData.MaleTitles)
break
case Female:
title = randomFrom(jsonData.FemaleTitles)
break
default:
title = FirstName(privateRand.Intn(2))
break
}
return title
} | [
"func",
"Title",
"(",
"gender",
"int",
")",
"string",
"{",
"var",
"title",
"=",
"\"",
"\"",
"\n",
"switch",
"gender",
"{",
"case",
"Male",
":",
"title",
"=",
"randomFrom",
"(",
"jsonData",
".",
"MaleTitles",
")",
"\n",
"break",
"\n",
"case",
"Female",
... | // Title returns a random title, gender decides the gender of the name | [
"Title",
"returns",
"a",
"random",
"title",
"gender",
"decides",
"the",
"gender",
"of",
"the",
"name"
] | 97a2356fcab20708fb8ae46cbbf69a5bc9feca63 | https://github.com/Pallinder/go-randomdata/blob/97a2356fcab20708fb8ae46cbbf69a5bc9feca63/random_data.go#L92-L106 |
5,399 | Pallinder/go-randomdata | random_data.go | FirstName | func FirstName(gender int) string {
var name = ""
switch gender {
case Male:
name = randomFrom(jsonData.FirstNamesMale)
break
case Female:
name = randomFrom(jsonData.FirstNamesFemale)
break
default:
name = FirstName(rand.Intn(2))
break
}
return name
} | go | func FirstName(gender int) string {
var name = ""
switch gender {
case Male:
name = randomFrom(jsonData.FirstNamesMale)
break
case Female:
name = randomFrom(jsonData.FirstNamesFemale)
break
default:
name = FirstName(rand.Intn(2))
break
}
return name
} | [
"func",
"FirstName",
"(",
"gender",
"int",
")",
"string",
"{",
"var",
"name",
"=",
"\"",
"\"",
"\n",
"switch",
"gender",
"{",
"case",
"Male",
":",
"name",
"=",
"randomFrom",
"(",
"jsonData",
".",
"FirstNamesMale",
")",
"\n",
"break",
"\n",
"case",
"Fem... | // FirstName returns a random first name, gender decides the gender of the name | [
"FirstName",
"returns",
"a",
"random",
"first",
"name",
"gender",
"decides",
"the",
"gender",
"of",
"the",
"name"
] | 97a2356fcab20708fb8ae46cbbf69a5bc9feca63 | https://github.com/Pallinder/go-randomdata/blob/97a2356fcab20708fb8ae46cbbf69a5bc9feca63/random_data.go#L109-L123 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.