为什么-8%-5的结果等于-3

时间:2017-02-24 15:30:32

标签: c

我有以下代码

InspectorDebugSession(10): StateChange: Start -> EntryPointBreakpointRegistered
InspectorDebugSession(10): Constructed
Launching 'BOABackgroundService.iOS' on 'iPhone 6 iOS 9.3'...
InspectorDebugSession(10): HandleTargetEvent: TargetReady
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Xamarin.iOS.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.dll [External]
Resolved pending breakpoint for 'UIKit.UIApplication.Main(string[], string, string)' to /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:61 [0x00000].
Resolved pending breakpoint for 'UIKit.UIApplication.Main(string[], System.Type, System.Type)' to /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:68 [0x00000].
Resolved pending breakpoint for 'UIKit.UIApplication.Main(string[])' to /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:73 [0x00000].
Resolved pending breakpoint for 'UIKit.UIApplication.Main(string[], System.IntPtr, System.IntPtr)' to /Users/builder/data/lanes/3985/35d1ccd0/source/xamarin-macios/src/UIKit/UIApplication.cs:78 [0x00000].
Thread started:  #2
InspectorDebugSession(10): HandleTargetEvent: ThreadStarted
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/BOABackgroundService.iOS.exe
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Xamarin.Forms.Platform.iOS.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/BOABackgroundService.dll
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Xamarin.Forms.Core.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Runtime.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.ObjectModel.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Core.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Xml.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Mono.Dynamic.Interpreter.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.ComponentModel.Composition.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Collections.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Diagnostics.Debug.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Threading.Tasks.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Globalization.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.ComponentModel.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Xml.ReaderWriter.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Reflection.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Linq.Expressions.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.IO.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Dynamic.Runtime.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Threading.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Net.Http.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Runtime.Serialization.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.ServiceModel.Internals.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Runtime.Extensions.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Linq.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Reflection.Extensions.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Resources.ResourceManager.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Diagnostics.Tools.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Microsoft.AspNet.SignalR.Client.dll [External]
2017-02-24 16:17:57.572 BOABackgroundService.iOS[19278:262973] Could not find `Newtonsoft.Json` referenced by assembly `Microsoft.AspNet.SignalR.Client, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4704e1264c0eb6e1`.
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Net.Http.Extensions.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/System.Text.RegularExpressions.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Plugin.DeviceInfo.dll [External]
Loaded assembly: /Users/username/Library/Developer/CoreSimulator/Devices/BEC706BF-2E76-4269-B4E5-49A4AD84DBA6/data/Containers/Bundle/Application/13748412-CF6A-4D26-B8AD-A4B4605174E7/BOABackgroundService.iOS.app/.monotouch-64/Plugin.DeviceInfo.Abstractions.dll [External]
InspectorDebugSession(10): HandleTargetEvent: TargetHitBreakpoint
InspectorDebugSession(10): StateChange: EntryPointBreakpointRegistered -> EntryPointBreakpointHit
InspectorDebugSession(10): AgentBridge.InjectAssembly: /Library/Frameworks/Xamarin.Interactive.framework/Versions/Current/Agents/iOS/Xamarin.Interactive.iOS.dll
InspectorDebugSession(10): StateChange: EntryPointBreakpointHit -> BreakdanceInvoking
Loaded assembly: /Library/Frameworks/Xamarin.Interactive.framework/Versions/Current/Agents/iOS/Xamarin.Interactive.iOS.dll [External]
Loaded assembly: /Library/Frameworks/Xamarin.Interactive.framework/Versions/Current/Agents/iOS/Xamarin.Interactive.dll [External]
InspectorDebugSession(10): StateChange: BreakdanceInvoking -> BreakdanceStarted
Thread started: <Thread Pool> #4
InspectorDebugSession(10): HandleTargetEvent: ThreadStarted
Thread started: <Thread Pool> #5
InspectorDebugSession(10): HandleTargetEvent: ThreadStarted
Thread started: <Thread Pool> #6
InspectorDebugSession(10): HandleTargetEvent: ThreadStarted
2017-02-24 16:18:00.261 BOABackgroundService.iOS[19278:262973] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
    /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2017-02-24 16:18:00.262 BOABackgroundService.iOS[19278:262973] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fb09790bb40 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2017-02-24 16:18:00.263 BOABackgroundService.iOS[19278:262973] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
    /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2017-02-24 16:18:00.263 BOABackgroundService.iOS[19278:262973] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fb09790bb40 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2017-02-24 16:18:00.264 BOABackgroundService.iOS[19278:262973] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
    /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2017-02-24 16:18:00.264 BOABackgroundService.iOS[19278:262973] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fb09790bb40 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2017-02-24 16:18:00.265 BOABackgroundService.iOS[19278:262973] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
    /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2017-02-24 16:18:00.265 BOABackgroundService.iOS[19278:262973] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fb09790bb40 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
2017-02-24 16:18:00.266 BOABackgroundService.iOS[19278:262973] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib:  dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found.  Did find:
    /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator
2017-02-24 16:18:00.266 BOABackgroundService.iOS[19278:262973] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fb09790bb40 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded)
InspectorDebugSession(10): HandleTargetEvent: UnhandledException
Unhandled Exception:

Foundation.ModelNotImplementedException: Exception of type 'Foundation.ModelNotImplementedException' was thrown.

Thread finished: <Thread Pool> #6
InspectorDebugSession(10): HandleTargetEvent: ThreadStopped
Thread finished: <Thread Pool> #5
InspectorDebugSession(10): HandleTargetEvent: ThreadStopped
The thread 'Unknown' (0x6) has exited with code 0 (0x0).
The thread 'Unknown' (0x5) has exited with code 0 (0x0).
Thread finished: <Thread Pool> #4
InspectorDebugSession(10): HandleTargetEvent: ThreadStopped
The thread 'Unknown' (0x4) has exited with code 0 (0x0).

我得到的输出是

#include <stdio.h>

int main(void)
{

    printf("%d\n", -8%5);


    printf("%d\n", 8%-5);

    printf("%d\n", -8%-5);


    return 0;
}

如何-8%5和8%-5有不同的符号,特别是当-8/5和8 / -5的结果具有相同的输出时?

同样为什么-8%-5给-3作为输出,当-8 / -5给出它的输出为1?

1 个答案:

答案 0 :(得分:0)

如果两个操作数都是非负的,那么余数是非负的;如果没有,余数的符号是​​实现定义的。